-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,46 @@ | ||
import qualified Data.ByteString.Lazy as LBS | ||
import qualified Data.ByteString.Lazy.Char8 as LBS8 | ||
import GLua.AG.Token (Region (..)) | ||
import qualified GLuaFixer.Interface as GLua | ||
import GLuaFixer.LintMessage ( | ||
Issue (..), | ||
LintMessage (..), | ||
Severity (..), | ||
) | ||
import GLuaFixer.LintSettings (LintSettings, defaultLintSettings) | ||
import Test.Tasty (TestTree, defaultMain, testGroup) | ||
import Test.Tasty.HUnit (testCase, (@=?)) | ||
import Text.ParserCombinators.UU.BasicInstances (LineColPos (..)) | ||
|
||
main :: IO () | ||
main = defaultMain tests | ||
|
||
tests :: TestTree | ||
tests = testGroup "Unit tests" [testQuotedStringWarningPosition] | ||
|
||
-- | Regression test for https://github.com/FPtje/GLuaFixer/issues/169 | ||
testQuotedStringWarningPosition :: TestTree | ||
testQuotedStringWarningPosition = | ||
testCase "Assert that the warning is thrown and in the right region" $ | ||
let | ||
input = "bar = a or b\nfoo = \"\" and \"\" and \"dddd\" || \"[]\"" | ||
expectedRegion = Region (LineColPos 1 27 40) (LineColPos 1 29 42) | ||
warning = SyntaxInconsistency "||" "or" | ||
msg = LintMessage LintWarning expectedRegion warning testFilePath | ||
in | ||
lintString input @=? [msg] | ||
|
||
-- | Helper to lint a string | ||
lintString :: String -> [LintMessage] | ||
lintString input = | ||
let | ||
settings = defaultLintSettings | ||
in | ||
case GLua.lex settings testFilePath input of | ||
Left errs -> errs | ||
Right mTokens -> case GLua.parse settings testFilePath mTokens of | ||
Left errs -> errs | ||
Right ast -> GLua.lexiconLint testFilePath settings mTokens <> GLua.astLint testFilePath settings ast | ||
|
||
testFilePath :: String | ||
testFilePath = "test input" |