mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-26 10:35:04 +03:00
49 lines
2.1 KiB
Haskell
49 lines
2.1 KiB
Haskell
module Parser.JsImportTest where
|
|
|
|
import Test.Tasty.Hspec
|
|
|
|
import Data.Either (isLeft)
|
|
import Path.Posix (relfile)
|
|
|
|
import Parser.Common (runWaspParser)
|
|
import Parser.JsImport (jsImport)
|
|
import qualified StrongPath as SP
|
|
import qualified Wasp
|
|
|
|
|
|
spec_parseJsImport :: Spec
|
|
spec_parseJsImport = do
|
|
let someFilePath = SP.fromPathRelFileP [relfile|some/file.js|]
|
|
|
|
it "Parses external code js import with default import correctly" $ do
|
|
runWaspParser jsImport "import something from \"@ext/some/file.js\""
|
|
`shouldBe` Right (Wasp.JsImport (Just "something") [] someFilePath)
|
|
|
|
it "Parses correctly when there is whitespace up front" $ do
|
|
runWaspParser jsImport " import something from \"@ext/some/file.js\""
|
|
`shouldBe` Right (Wasp.JsImport (Just "something") [] someFilePath)
|
|
|
|
it "Parses correctly when 'from' is part of WHAT part" $ do
|
|
runWaspParser jsImport "import somethingfrom from \"@ext/some/file.js\""
|
|
`shouldBe` Right (Wasp.JsImport (Just "somethingfrom") [] someFilePath)
|
|
|
|
it "Parses correctly when 'what' is a single named export" $ do
|
|
runWaspParser jsImport "import { something } from \"@ext/some/file.js\""
|
|
`shouldBe` Right (Wasp.JsImport Nothing ["something"] someFilePath)
|
|
|
|
it "For now we don't support multiple named exports in WHAT part" $ do
|
|
isLeft (runWaspParser jsImport "import { foo, bar } from \"@ext/some/file.js\"")
|
|
`shouldBe` True
|
|
|
|
it "Throws error if there is no whitespace after import" $ do
|
|
isLeft (runWaspParser jsImport "importsomething from \"@ext/some/file.js\"")
|
|
`shouldBe` True
|
|
|
|
it "Throws error if 'from' part is not referring to the external code" $ do
|
|
isLeft (runWaspParser jsImport "import something from \"some/file.js\"")
|
|
`shouldBe` True
|
|
|
|
it "For now we don't support single quotes in FROM part (TODO: support them in the future!)" $ do
|
|
isLeft (runWaspParser jsImport "import something from '@ext/some/file.js'")
|
|
`shouldBe` True
|