summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreyChudnov <>2013-08-28 19:59:57 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2013-08-28 19:59:57 (GMT)
commit42d63c7500a9ae02a2fa33595eeaedf8b13987ab (patch)
treee9a6a2ae98fcb6d2012e4bc47613fc3cbfc42cba
parent10697c6766ac629688ad35035f0f1ad95f789957 (diff)
version 0.15.20.15.2
-rw-r--r--CHANGELOG4
-rw-r--r--language-ecmascript.cabal12
-rw-r--r--test/Test/Diff.hs58
-rw-r--r--test/Test/Pretty.hs43
-rw-r--r--test/Test/Unit.hs49
-rw-r--r--test/diff/expects/t1.diff2
6 files changed, 163 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 79e338b..d73cb69 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,9 @@
Version change log.
+=0.15.2=
+Fixed an error in the .cabal file that prevented some of the test modules
+to be packaged.
+
=0.15.1=
Added semicolons after the "return" statement in the pretty printer to
avoid certain class of syntax error when printed code is parsed
diff --git a/language-ecmascript.cabal b/language-ecmascript.cabal
index c87b508..987df95 100644
--- a/language-ecmascript.cabal
+++ b/language-ecmascript.cabal
@@ -1,5 +1,5 @@
Name: language-ecmascript
-Version: 0.15.1
+Version: 0.15.2
Cabal-Version: >= 1.10
Copyright: (c) 2007-2012 Brown University, (c) 2008-2010 Claudiu Saftoiu,
(c) 2012-2013 Stevens Institute of Technology
@@ -19,8 +19,8 @@ Synopsis: JavaScript parser and pretty-printer library
Description:
Tools for working with ECMAScript 3 (popularly known as JavaScript).
Includes a parser, pretty-printer, tools for working with source tree
- annotations and an arbitrary instance. Analyses have migrated to
- language-ecmascript-analysis
+ annotations and an arbitrary instance. See CHANGELOG for a summary of
+ changes.
Source-repository head
type: git
@@ -29,7 +29,7 @@ Source-repository head
Source-repository this
type: git
location: git://github.com/jswebtools/language-ecmascript.git
- tag: 0.15.1
+ tag: 0.15.2
Library
Hs-Source-Dirs:
@@ -70,6 +70,10 @@ Test-Suite test
Hs-Source-Dirs: test
Type: exitcode-stdio-1.0
Main-Is: TestMain.hs
+ Other-Modules:
+ Test.Diff
+ Test.Unit
+ Test.Pretty
Build-Depends:
base >= 4 && < 5,
mtl >= 1.1.0.1,
diff --git a/test/Test/Diff.hs b/test/Test/Diff.hs
new file mode 100644
index 0000000..bdc092f
--- /dev/null
+++ b/test/Test/Diff.hs
@@ -0,0 +1,58 @@
+module Test.Diff where
+
+import Test.HUnit hiding (Test)
+import Test.Framework
+import Test.Framework.Providers.HUnit
+import System.Exit
+import System.Directory
+import qualified System.FilePath as FP
+import Language.ECMAScript3.Parser
+import Language.ECMAScript3.PrettyPrint
+import Language.ECMAScript3.Syntax
+import Language.ECMAScript3.Syntax.Annotations
+import Language.ECMAScript3.SourceDiff
+import Control.Monad
+
+tests_diff :: Test
+tests_diff =
+ buildTest $
+ do allLefts <- getDirectoryContents leftDir
+ allRights <- getDirectoryContents rightDir
+ allDiffs <- getDirectoryContents expectsDir
+ let validLefts = getValidJS allLefts
+ let validRights = getValidJS allRights
+ let validDiffs = getValidDiffs allDiffs
+ return $ testGroup "Source Diff tests" $
+ map genTest $ filter ((`elem` (map FP.dropExtension validDiffs)) .
+ FP.dropExtension)
+ $ filter (`elem` validRights) validLefts
+ where getValidJS = filter $ \x -> FP.takeExtension x == ".js"
+ getValidDiffs = filter $ \x -> FP.takeExtension x == ".diff"
+
+leftDir = "test/diff/left"
+rightDir = "test/diff/right"
+expectsDir = "test/diff/expects"
+
+genTest :: FilePath -> Test
+genTest testFileName = testCase testFileName $
+ diffTest (leftDir `FP.combine` testFileName)
+ (rightDir `FP.combine` testFileName)
+ (expectsDir `FP.combine`
+ ((FP.dropExtension testFileName)
+ `FP.addExtension` "diff"))
+
+diffTest :: FilePath -> FilePath -> FilePath -> Assertion
+diffTest leftFile rightFile diffFile =
+ do left <- readFile leftFile
+ right <- readFile rightFile
+ expect<- readFile diffFile
+ let x = do ljs <- parseFromString left
+ rjs <- parseFromString right
+ return (removeAnnotations ljs, removeAnnotations rjs)
+ case x of
+ Left err -> assertFailure $ "Parsing error: " ++ (show err)
+ Right (ljs, rjs) ->
+ let diff = jsDiff ljs rjs
+ msg = "Failed to match diff output to an expected one. Expected:\n"
+ ++ expect ++ "\nSaw:\n" ++ diff
+ in unless (diff == expect) (assertFailure msg)
diff --git a/test/Test/Pretty.hs b/test/Test/Pretty.hs
new file mode 100644
index 0000000..2706f4c
--- /dev/null
+++ b/test/Test/Pretty.hs
@@ -0,0 +1,43 @@
+module Test.Pretty where
+
+import Test.Framework
+import Test.Framework.Providers.QuickCheck2
+import Language.ECMAScript3.Parser
+import Language.ECMAScript3.PrettyPrint
+import Language.ECMAScript3.Syntax
+import Language.ECMAScript3.Syntax.Arbitrary()
+import Language.ECMAScript3.Syntax.Annotations
+--import System.Exit
+import Language.ECMAScript3.SourceDiff
+import Test.QuickCheck
+
+tests_pretty :: Test
+tests_pretty = testProperty "Parse is the inverse of pretty" prettyParseEquivalence
+
+-- main :: IO ()
+-- main =
+-- let qcArgs = Args {maxSuccess = 50
+-- ,maxDiscardRatio = 10
+-- ,maxSize = 10
+-- ,replay = Nothing
+-- ,chatty = False}
+-- in quickCheckWithResult qcArgs prettyParseEquivalence >>= \res ->
+-- case res of
+-- Success {} -> putStrLn "All tests passes"
+-- GaveUp {} -> putStrLn "Gave up"
+-- Failure {} -> putStrLn "Test failed" >> exitFailure
+-- NoExpectedFailure {} -> putStrLn "Unexpected failure" >> exitFailure
+
+prettyParseEquivalence :: JavaScript () -> Property
+prettyParseEquivalence orig =
+ let pp = show $ prettyPrint orig
+ in case parseFromString pp of
+ Left e ->
+ let err = "Can't parse pretty-printed code. The error was: " ++ (show e) ++
+ "\nThe pretty-printed code in question:\n" ++ pp
+ in whenFail (putStrLn err) False
+ Right parsed ->
+ let eq = (removeAnnotations parsed) == orig
+ msg ="The parse of the pretty-printed AST didn't match the original\n"
+ ++"Diff:\n" ++ jsDiff orig (reannotate (const ()) parsed)
+ in whenFail (putStrLn msg) eq
diff --git a/test/Test/Unit.hs b/test/Test/Unit.hs
new file mode 100644
index 0000000..94159fa
--- /dev/null
+++ b/test/Test/Unit.hs
@@ -0,0 +1,49 @@
+module Test.Unit where
+
+import Test.Framework
+import Test.Framework.Providers.HUnit
+import Test.HUnit hiding (Test)
+import System.Exit
+import System.Directory
+import qualified System.FilePath as FilePath
+import Language.ECMAScript3.Parser
+import Language.ECMAScript3.PrettyPrint
+import Language.ECMAScript3.Syntax
+import Language.ECMAScript3.Syntax.Annotations
+import Language.ECMAScript3.SourceDiff
+import Control.Monad
+
+
+tests_unit :: Test
+tests_unit =
+ buildTest $
+ do allFiles <- getDirectoryContents testDir
+ let validFiles = filter (\x -> FilePath.takeExtension x == ".js") allFiles
+ return $ testGroup "Parser Unit tests" $ map genTest validFiles
+
+
+genTest :: FilePath -> Test
+genTest file = testCase file $ parsePrettyTest (testDir `FilePath.combine` file)
+
+testDir = "test/parse-pretty"
+
+-- | tests the parser with pre-defined test-cases
+parsePrettyTest :: FilePath -> Assertion
+parsePrettyTest filename =
+ readFile filename >>= \src ->
+ case parseFromString src of
+ Left err -> assertFailure $ "Can't parse a test-case: " ++ filename
+ Right js -> let str = show $ prettyPrint js
+ in case parseFromString str of
+ Left err ->
+ let msg = "Can't parse pretty-printed code. The error was: "
+ ++ (show err)
+ ++ "\nThe pretty-printed code in question:\n" ++ str
+ in assertFailure msg
+ Right js' -> do
+ let str' = show $ prettyPrint js'
+ unless (str == str') $ do
+ let msg = "The parse of the pretty-printed AST didn't match the original\n"
+ ++ "Diff:\n" ++ jsDiff js js'
+ assertFailure msg
+
diff --git a/test/diff/expects/t1.diff b/test/diff/expects/t1.diff
index a864660..ccd6d4f 100644
--- a/test/diff/expects/t1.diff
+++ b/test/diff/expects/t1.diff
@@ -1,2 +1,2 @@
2d1
-< y = 2; \ No newline at end of file
+< y = 2;