This repository was archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Make sure we only import
directory
#40
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module SqlSquared.Path | ||
( AnyFilePath | ||
, AnyDirPath | ||
, parseAnyFilePath | ||
, printAnyFilePath | ||
, parseAnyDirPath | ||
, printAnyDirPath | ||
, genAnyFilePath | ||
, genAnyDirPath | ||
) where | ||
|
||
import Prelude | ||
import Data.Either as E | ||
import Data.NonEmpty ((:|)) | ||
import Data.Path.Pathy as Pt | ||
import Data.Path.Pathy.Gen as PtGen | ||
import Control.Monad.Gen as Gen | ||
import Control.Monad.Rec.Class (class MonadRec) | ||
import SqlSquared.Utils ((∘)) | ||
|
||
type AnyDirPath = E.Either (Pt.AbsDir Pt.Unsandboxed) (Pt.RelDir Pt.Unsandboxed) | ||
type AnyFilePath = E.Either (Pt.AbsFile Pt.Unsandboxed) (Pt.RelFile Pt.Unsandboxed) | ||
|
||
printAnyDirPath :: AnyDirPath -> String | ||
printAnyDirPath = E.either Pt.unsafePrintPath Pt.unsafePrintPath | ||
|
||
parseAnyDirPath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyDirPath | ||
parseAnyDirPath fail = Pt.parsePath | ||
(pure ∘ E.Right) | ||
(pure ∘ E.Left) | ||
(const $ fail "Expected a directory path") | ||
(const $ fail "Expected a directory path") | ||
|
||
printAnyFilePath :: AnyFilePath -> String | ||
printAnyFilePath = E.either Pt.unsafePrintPath Pt.unsafePrintPath | ||
|
||
parseAnyFilePath :: forall m. Applicative m => (forall a. String -> m a) -> String -> m AnyFilePath | ||
parseAnyFilePath fail = Pt.parsePath | ||
(const $ fail "Expected a file path") | ||
(const $ fail "Expected a file path") | ||
(pure ∘ E.Right) | ||
(pure ∘ E.Left) | ||
|
||
genAnyFilePath :: forall m. Gen.MonadGen m => MonadRec m => m AnyFilePath | ||
genAnyFilePath = Gen.oneOf | ||
$ (E.Left ∘ Pt.unsandbox <$> PtGen.genAbsFilePath) | ||
:| [E.Right ∘ Pt.unsandbox <$> PtGen.genRelFilePath] | ||
|
||
genAnyDirPath :: forall m. Gen.MonadGen m => MonadRec m => m AnyDirPath | ||
genAnyDirPath = Gen.oneOf | ||
$ (E.Left ∘ Pt.unsandbox <$> PtGen.genAbsDirPath) | ||
:| [E.Right ∘ Pt.unsandbox <$> PtGen.genRelDirPath] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,25 @@ parseFail s = | |
E.Left err → pure unit | ||
E.Right (sql ∷ SqlQuery) → Assert.assert s false | ||
|
||
parseFailWith ∷ ∀ e. String → String → TestSuite (testOutput ∷ Console.TESTOUTPUT | e) | ||
parseFailWith s err = | ||
test "parse/failWith" | ||
case parseQuery s of | ||
E.Left err' → | ||
if show err' == err | ||
then pure unit | ||
else Assert.assert | ||
("expected query:" <> s <> | ||
"\n\n to fail input error: " <> err <> | ||
"\n\n but instead fot error: " <> show err') | ||
false | ||
E.Right (sql ∷ SqlQuery) → | ||
Assert.assert | ||
("expected to fail with:" <> err <> | ||
"\n\tbut input query:" <> s <> | ||
"\n\twas parsed as:" <> printQuery sql) | ||
false | ||
|
||
testSuite ∷ ∀ e. TestSuite (testOutput ∷ Console.TESTOUTPUT | e) | ||
testSuite = suite "parsers" do | ||
testSuite1 | ||
|
@@ -51,6 +70,14 @@ testSuite = suite "parsers" do | |
|
||
testSuite1 ∷ ∀ e. TestSuite (testOutput ∷ Console.TESTOUTPUT | e) | ||
testSuite1 = do | ||
parseFailWith """ | ||
import `/path/To/Your/File/myModule`; SELECT id("HELLO") | ||
""" "(ParseError \"Expected a directory path\" (Position { line: 2, column: 12 }))" | ||
|
||
parseSucc """ | ||
import `/path/To/Your/File/myModule/`; SELECT id("HELLO") | ||
""" | ||
|
||
parseSucc """ | ||
a := 1; SELECT * FROM `/test` | ||
""" | ||
|
@@ -157,6 +184,10 @@ testSuite1 = do | |
""" | ||
|
||
parseSucc """ | ||
import `foo/`; select * from `/test` | ||
""" | ||
|
||
parseFail """ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BREAKING. Is there a way to not make it braking? |
||
import foo; select * from `/test` | ||
""" | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BREAKING. As new constraint is introduced (that's needed for generating of path-es)