aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2019-04-13 09:51:41 -0400
committerEduardo Julian2019-04-13 09:51:41 -0400
commit89c3fc64f1e1648b57a7f208a7499e4e2b1c9135 (patch)
tree064c3ff70d555c315ba7b68f8e4f34d44ab053ab /stdlib
parentf3957974e63756a7dce0239b3a5bdbaa40e62d5e (diff)
Started porting tests for "lux/tool".
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/test/lux.lux24
-rw-r--r--stdlib/source/test/lux/compiler/default/syntax.lux147
-rw-r--r--stdlib/source/test/lux/tool.lux28
-rw-r--r--stdlib/source/test/lux/tool/compiler/default/syntax.lux152
4 files changed, 183 insertions, 168 deletions
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index d9b3df35e..77f0e1bbd 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -123,31 +123,11 @@
["#." macro]
["#." math]
["#." time]
+ ["#." tool]
["#." type]
["#." world]
["#." host
["#/." jvm]]]
- ## [control
- ## [concurrency
- ## ## [semaphore (#+)]
- ## ]]
- ## [compiler
- ## [default
- ## ["_default/." syntax]
- ## [phase
- ## [analysis
- ## ["_.A" primitive]
- ## ["_.A" structure]
- ## ["_.A" reference]
- ## ["_.A" case]
- ## ["_.A" function]
- ## [procedure
- ## ["_.A" common]]]
- ## [synthesis
- ## ["_.S" primitive]
- ## ["_.S" structure]
- ## ["_.S" case]
- ## ["_.S" function]]]]]
))
(def: identity
@@ -368,6 +348,8 @@
/math.test
(<| (_.context "/time")
/time.test)
+ (<| (_.context "/tool")
+ /tool.test)
/type.test
/world.test
(<| (_.context "/host")
diff --git a/stdlib/source/test/lux/compiler/default/syntax.lux b/stdlib/source/test/lux/compiler/default/syntax.lux
deleted file mode 100644
index 530bbfbad..000000000
--- a/stdlib/source/test/lux/compiler/default/syntax.lux
+++ /dev/null
@@ -1,147 +0,0 @@
-(.module:
- [lux #*
- [control
- [monad (#+ do)]]
- [data
- ["." error]
- ["." text
- format
- ["l" lexer]]
- [collection
- ["." list]
- ["." dictionary (#+ Dictionary)]]]
- [math
- ["r" random ("#;." monad)]]
- [macro
- ["." code]]
- [compiler
- [default
- ["&" syntax]]]
- test])
-
-(def: default-cursor
- Cursor
- {#.module ""
- #.line 0
- #.column 0})
-
-(def: name-part^
- (r.Random Text)
- (do r.monad
- [#let [digits "0123456789"
- delimiters (format "()[]{}#." &.text-delimiter)
- space (format " " text.new-line)
- invalid-range (format digits delimiters space)
- char-gen (|> r.nat
- (:: @ map (|>> (n/% 256) (n/max 1)))
- (r.filter (function (_ sample)
- (not (text.contains? (text.from-code sample)
- invalid-range)))))]
- size (|> r.nat (:: @ map (|>> (n/% 20) (n/max 1))))]
- (r.text char-gen size)))
-
-(def: name^
- (r.Random Name)
- (r.and name-part^ name-part^))
-
-(def: code^
- (r.Random Code)
- (let [numeric^ (: (r.Random Code)
- ($_ r.either
- (|> r.bit (r;map code.bit))
- (|> r.nat (r;map code.nat))
- (|> r.int (r;map code.int))
- (|> r.rev (r;map code.rev))
- (|> r.frac (r;map code.frac))))
- textual^ (: (r.Random Code)
- ($_ r.either
- (do r.monad
- [size (|> r.nat (r;map (n/% 20)))]
- (|> (r.unicode size) (r;map code.text)))
- (|> name^ (r;map code.identifier))
- (|> name^ (r;map code.tag))))
- simple^ (: (r.Random Code)
- ($_ r.either
- numeric^
- textual^))]
- (r.rec
- (function (_ code^)
- (let [multi^ (do r.monad
- [size (|> r.nat (r;map (n/% 3)))]
- (r.list size code^))
- composite^ (: (r.Random Code)
- ($_ r.either
- (|> multi^ (r;map code.form))
- (|> multi^ (r;map code.tuple))
- (do r.monad
- [size (|> r.nat (r;map (n/% 3)))]
- (|> (r.list size (r.and code^ code^))
- (r;map code.record)))))]
- (r.either simple^
- composite^))))))
-
-(context: "Lux code syntax."
- (<| (times 100)
- (do @
- [sample code^
- other code^]
- ($_ seq
- (test "Can parse Lux code."
- (case (let [source-code (%code sample)]
- (&.parse "" (dictionary.new text.hash) (text.size source-code)
- [default-cursor 0 source-code]))
- (#error.Failure error)
- #0
-
- (#error.Success [_ parsed])
- (:: code.equivalence = parsed sample)))
- (test "Can parse Lux multiple code nodes."
- (let [source-code (format (%code sample) " " (%code other))
- source-code//size (text.size source-code)]
- (case (&.parse "" (dictionary.new text.hash) source-code//size
- [default-cursor 0 source-code])
- (#error.Failure error)
- #0
-
- (#error.Success [remaining =sample])
- (case (&.parse "" (dictionary.new text.hash) source-code//size
- remaining)
- (#error.Failure error)
- #0
-
- (#error.Success [_ =other])
- (and (:: code.equivalence = sample =sample)
- (:: code.equivalence = other =other))))))
- ))))
-
-(def: comment-text^
- (r.Random Text)
- (let [char-gen (|> r.nat (r.filter (|>> (n/= (`` (char (~~ (static text.new-line))))) not)))]
- (do r.monad
- [size (|> r.nat (r;map (n/% 20)))]
- (r.text char-gen size))))
-
-(def: comment^
- (r.Random Text)
- (do r.monad
- [comment comment-text^]
- (wrap (format "## " comment text.new-line))))
-
-(context: "Multi-line text & comments."
- (<| (seed 12137892244981970631)
- ## (times 100)
- (do @
- [sample code^
- comment comment^]
- ($_ seq
- (test "Can handle comments."
- (case (let [source-code (format comment (%code sample))
- source-code//size (text.size source-code)]
- (&.parse "" (dictionary.new text.hash) source-code//size
- [default-cursor 0 source-code]))
- (#error.Failure error)
- #0
-
- (#error.Success [_ parsed])
- (:: code.equivalence = parsed sample)))
- ))))
diff --git a/stdlib/source/test/lux/tool.lux b/stdlib/source/test/lux/tool.lux
new file mode 100644
index 000000000..340e24642
--- /dev/null
+++ b/stdlib/source/test/lux/tool.lux
@@ -0,0 +1,28 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]]
+ ## [compiler
+ ## [phase
+ ## [analysis
+ ## ["_.A" primitive]
+ ## ["_.A" structure]
+ ## ["_.A" reference]
+ ## ["_.A" case]
+ ## ["_.A" function]
+ ## [procedure
+ ## ["_.A" common]]]
+ ## [synthesis
+ ## ["_.S" primitive]
+ ## ["_.S" structure]
+ ## ["_.S" case]
+ ## ["_.S" function]]]]
+ ["." / #_
+ [compiler
+ [default
+ ["#." syntax]]]])
+
+(def: #export test
+ Test
+ ($_ _.and
+ /syntax.test
+ ))
diff --git a/stdlib/source/test/lux/tool/compiler/default/syntax.lux b/stdlib/source/test/lux/tool/compiler/default/syntax.lux
new file mode 100644
index 000000000..632e97023
--- /dev/null
+++ b/stdlib/source/test/lux/tool/compiler/default/syntax.lux
@@ -0,0 +1,152 @@
+(.module:
+ [lux #*
+ data/text/format
+ [abstract/monad (#+ do)]
+ ["r" math/random (#+ Random) ("#@." monad)]
+ ["_" test (#+ Test)]
+ [data
+ ["." error]
+ ["." text
+ ["l" lexer]]
+ [collection
+ ["." list]
+ ["." dictionary (#+ Dictionary)]]]
+ [macro
+ ["." code]]]
+ {1
+ ["." /]})
+
+(def: default-cursor
+ Cursor
+ {#.module ""
+ #.line 0
+ #.column 0})
+
+(def: name-part^
+ (Random Text)
+ (do r.monad
+ [#let [digits "0123456789"
+ delimiters (format "()[]{}#." /.text-delimiter)
+ space (format " " text.new-line)
+ invalid-range (format digits delimiters space)
+ char-gen (|> r.nat
+ (:: @ map (|>> (n/% 256) (n/max 1)))
+ (r.filter (function (_ sample)
+ (not (text.contains? (text.from-code sample)
+ invalid-range)))))]
+ size (|> r.nat (:: @ map (|>> (n/% 20) (n/max 1))))]
+ (r.text char-gen size)))
+
+(def: name^
+ (Random Name)
+ (r.and name-part^ name-part^))
+
+(def: code^
+ (Random Code)
+ (let [numeric^ (: (Random Code)
+ ($_ r.either
+ (|> r.bit (r@map code.bit))
+ (|> r.nat (r@map code.nat))
+ (|> r.int (r@map code.int))
+ (|> r.rev (r@map code.rev))
+ (|> r.frac (r@map code.frac))))
+ textual^ (: (Random Code)
+ ($_ r.either
+ (do r.monad
+ [size (|> r.nat (r@map (n/% 20)))]
+ (|> (r.unicode size) (r@map code.text)))
+ (|> name^ (r@map code.identifier))
+ (|> name^ (r@map code.tag))))
+ simple^ (: (Random Code)
+ ($_ r.either
+ numeric^
+ textual^))]
+ (r.rec
+ (function (_ code^)
+ (let [multi^ (do r.monad
+ [size (|> r.nat (r@map (n/% 3)))]
+ (r.list size code^))
+ composite^ (: (Random Code)
+ ($_ r.either
+ (|> multi^ (r@map code.form))
+ (|> multi^ (r@map code.tuple))
+ (do r.monad
+ [size (|> r.nat (r@map (n/% 3)))]
+ (|> (r.list size (r.and code^ code^))
+ (r@map code.record)))))]
+ ($_ r.either
+ simple^
+ composite^))))))
+
+(def: code
+ Test
+ (do r.monad
+ [sample code^]
+ ($_ _.and
+ (_.test "Can parse Lux code."
+ (case (let [source-code (%code sample)]
+ (/.parse "" (dictionary.new text.hash) (text.size source-code)
+ [default-cursor 0 source-code]))
+ (#error.Failure error)
+ false
+
+ (#error.Success [_ parsed])
+ (:: code.equivalence = parsed sample)))
+ (do @
+ [other code^]
+ (_.test "Can parse Lux multiple code nodes."
+ (let [source-code (format (%code sample) " " (%code other))
+ source-code//size (text.size source-code)]
+ (case (/.parse "" (dictionary.new text.hash) source-code//size
+ [default-cursor 0 source-code])
+ (#error.Failure error)
+ false
+
+ (#error.Success [remaining =sample])
+ (case (/.parse "" (dictionary.new text.hash) source-code//size
+ remaining)
+ (#error.Failure error)
+ false
+
+ (#error.Success [_ =other])
+ (and (:: code.equivalence = sample =sample)
+ (:: code.equivalence = other =other)))))))
+ )))
+
+(def: comment-text^
+ (Random Text)
+ (let [char-gen (|> r.nat (r.filter (|>> (n/= (`` (char (~~ (static text.new-line))))) not)))]
+ (do r.monad
+ [size (|> r.nat (r@map (n/% 20)))]
+ (r.text char-gen size))))
+
+(def: comment^
+ (Random Text)
+ (do r.monad
+ [comment comment-text^]
+ (wrap (format "## " comment text.new-line))))
+
+(def: comments
+ Test
+ (do r.monad
+ [sample code^
+ comment comment^]
+ ($_ _.and
+ (_.test "Can handle comments."
+ (case (let [source-code (format comment (%code sample))
+ source-code//size (text.size source-code)]
+ (/.parse "" (dictionary.new text.hash) source-code//size
+ [default-cursor 0 source-code]))
+ (#error.Failure error)
+ false
+
+ (#error.Success [_ parsed])
+ (:: code.equivalence = parsed sample)))
+ )))
+
+(def: #export test
+ Test
+ ($_ _.and
+ ..code
+ ..comments
+ ))