File tree Expand file tree Collapse file tree 6 files changed +48
-19
lines changed Expand file tree Collapse file tree 6 files changed +48
-19
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ module Copager2.Prelude
1212 , tokenQQ
1313 , RuleSet (.. )
1414 , ruleQQ
15+ , IR
1516 ) where
1617
1718import Copager2.Core.Processor (Processor , ProcessorT (.. ), runProcessor )
@@ -20,3 +21,4 @@ import Copager2.Core.Language.Token (TokenSet(..))
2021import Copager2.Core.Language.Token.QuasiQuote (tokenQQ )
2122import Copager2.Core.Language.Rule (RuleSet (.. ))
2223import Copager2.Core.Language.Rule.QuasiQuote (ruleQQ )
24+ import Copager2.Core.Language.IR (IR )
Original file line number Diff line number Diff line change 11module TestCase.Arithmetic (arithmetic ) where
22
3+ import Data.Bifunctor (first )
34import Data.Either.Combinators (swapEither )
45import Data.Functor.Identity (runIdentity )
56
@@ -8,12 +9,12 @@ import Copager2.IR.Void (Void)
89
910import Language.Arithmetic (ArithmeticToken , ArithmeticRule )
1011
11- import Utils (test )
12+ import TestCase. Utils (test , ok' , ng' )
1213
1314arithmetic :: Processor ArithmeticToken ArithmeticRule Void -> IO ()
1415arithmetic processor = do
15- let ok = runIdentity . runProcessor processor
16- ng = swapEither . ok
16+ let ok = ok' processor
17+ ng = ng' processor
1718
1819 test $ do
1920 ok " 10"
@@ -26,7 +27,6 @@ arithmetic processor = do
2627 ok " 10 * 20"
2728 ok " 10 / 20"
2829
29- test $ do
3030 ng " +"
3131 ng " (10"
3232 ng " ((((((10)))))"
Original file line number Diff line number Diff line change 11module TestCase.Json (json ) where
22
3+ import Data.Bifunctor (first )
34import Data.Either.Combinators (swapEither )
45import Data.Functor.Identity (runIdentity )
56
@@ -8,19 +9,18 @@ import Copager2.IR.Void (Void)
89
910import Language.Json (JsonToken , JsonRule )
1011
11- import Utils (test )
12+ import TestCase. Utils (test , ok' , ng' )
1213
1314json :: Processor JsonToken JsonRule Void -> IO ()
1415json processor = do
15- let ok = runIdentity . runProcessor processor
16- ng = swapEither . ok
16+ let ok = ok' processor
17+ ng = ng' processor
1718
1819 -- オブジェクト
1920 test $ do
2021 ok " { \" key\" : 10 }"
2122 ok " { \" key\" : { \" key\" : 10 } }"
2223
23- test $ do
2424 ng " { \" key\" : 10 "
2525 ng " { key: 10 }"
2626 ng " { \" key\" : 10, }"
@@ -32,7 +32,6 @@ json processor = do
3232 ok " [10, [20, 30]]"
3333 ok " [[[[10]]]]"
3434
35- test $ do
3635 ng " [10"
3736 ng " [10, 20, ]"
3837 ng " [[[[[10]]]]"
Original file line number Diff line number Diff line change 1+ module TestCase.Utils (test , ok' , ng' ) where
2+
3+ import Data.Function ((&) )
4+ import System.Exit (exitSuccess , exitFailure )
5+
6+ import Data.Bifunctor (first , second )
7+ import Data.Either.Combinators (swapEither )
8+ import Data.Functor.Identity (runIdentity )
9+
10+ import Copager2.Prelude
11+ import Copager2.Utils.Error (Copager2Error )
12+
13+ test :: (Show a ) => Either a b -> IO ()
14+ test (Right _) = return ()
15+ test (Left err) = do
16+ putStrLn $ " error: " ++ show err
17+ exitFailure
18+
19+ ok' :: (TokenSet ts , RuleSet ts rs , IR i )
20+ => Processor ts rs i
21+ -> String
22+ -> Either String ()
23+ ok' processor input =
24+ let f = runIdentity . runProcessor processor
25+ g = first (\ a -> " Expected success, but " ++ show a ++ " => " ++ input ++ " " )
26+ h = second (const () )
27+ in h . g . f $ input
28+
29+ ng' :: (TokenSet ts , RuleSet ts rs , IR i )
30+ => Processor ts rs i
31+ -> String
32+ -> Either String ()
33+ ng' processor input =
34+ let f = swapEither . runIdentity . runProcessor processor
35+ g = first (const $ " Unexpected success => " ++ input ++ " " )
36+ h = second (const () )
37+ in h . g . f $ input
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -22,4 +22,4 @@ test-suite standard
2222 other-modules :
2323 TestCase.Arithmetic,
2424 TestCase.Json,
25- Utils,
25+ TestCase. Utils,
You can’t perform that action at this time.
0 commit comments