diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 13 | ||||
-rw-r--r-- | tests/a_case_of_the_splits.py | 15 | ||||
-rw-r--r-- | tests/bodyClick.py | 18 | ||||
-rw-r--r-- | tests/bool.py | 17 | ||||
-rw-r--r-- | tests/bool.ur | 8 | ||||
-rw-r--r-- | tests/both.py | 12 | ||||
-rw-r--r-- | tests/both.ur | 5 | ||||
-rw-r--r-- | tests/both.urs | 1 | ||||
-rw-r--r-- | tests/both2.py | 12 | ||||
-rw-r--r-- | tests/both2.ur | 6 | ||||
-rw-r--r-- | tests/button.py | 13 | ||||
-rw-r--r-- | tests/case.py | 15 | ||||
-rw-r--r-- | tests/case.ur | 22 | ||||
-rw-r--r-- | tests/caseMod.py | 25 | ||||
-rw-r--r-- | tests/caseMod.ur | 8 | ||||
-rw-r--r-- | tests/ccheckbox.py | 15 | ||||
-rw-r--r-- | tests/ccheckbox.ur | 2 | ||||
-rw-r--r-- | tests/cdataF.py | 8 | ||||
-rw-r--r-- | tests/cdataF.ur | 8 | ||||
-rw-r--r-- | tests/cdataL.py | 18 | ||||
-rw-r--r-- | tests/cdataL.ur | 8 | ||||
-rw-r--r-- | tests/cffi.py | 37 | ||||
-rwxr-xr-x | tests/cffi.sh | 6 | ||||
-rw-r--r-- | tests/cffi.ur | 6 | ||||
-rw-r--r-- | tests/clib.urp | 2 | ||||
-rw-r--r-- | tests/test.c | 12 | ||||
-rw-r--r-- | tests/test.h | 2 |
27 files changed, 276 insertions, 38 deletions
diff --git a/tests/Makefile b/tests/Makefile index 03e37e4b..8df59518 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -7,6 +7,7 @@ test.o: test.c simple:: ./driver.sh aborter2 ./driver.sh aborter + ./driver.sh a_case_of_the_splits ./driver.sh activeBlock ./driver.sh activeFocus ./driver.sh active @@ -22,6 +23,17 @@ simple:: ./driver.sh autocomp ./driver.sh babySpawn ./driver.sh bindpat + ./driver.sh bodyClick + ./driver.sh bool + ./driver.sh both + ./driver.sh both2 + ./driver.sh button + ./driver.sh case + ./driver.sh caseMod + ./driver.sh ccheckbox + ./driver.sh cdataF + ./driver.sh cdataL + ./cffi.sh ./driver.sh DynChannel ./driver.sh jsonTest ./driver.sh entities @@ -29,4 +41,3 @@ simple:: ./driver.sh filter ./driver.sh jsbspace ./driver.sh utf8 - diff --git a/tests/a_case_of_the_splits.py b/tests/a_case_of_the_splits.py new file mode 100644 index 00000000..9a78e2fb --- /dev/null +++ b/tests/a_case_of_the_splits.py @@ -0,0 +1,15 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('main') + reg = self.xpath('button') + # click a couple of times + reg.click() + reg.click() + # we should get HTML spliced into HTML as-is (properly escaped even!) + span = self.xpath('span') + txt = span.text + self.assertRegex(txt, ".*\\(0\\).* :: .*\\(1\\).* :: \\[\\]") diff --git a/tests/bodyClick.py b/tests/bodyClick.py new file mode 100644 index 00000000..0c10d632 --- /dev/null +++ b/tests/bodyClick.py @@ -0,0 +1,18 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('main') + bd = self.driver.find_element_by_xpath('/html/body') + + bd.click() + alert = self.driver.switch_to.alert + self.assertEqual("You clicked the body.", alert.text) + alert.accept() + + bd.send_keys('h') + alert = self.driver.switch_to.alert + self.assertEqual("Key", alert.text) + alert.accept() diff --git a/tests/bool.py b/tests/bool.py new file mode 100644 index 00000000..e5fedf19 --- /dev/null +++ b/tests/bool.py @@ -0,0 +1,17 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('main') + l = self.xpath('li[1]/a') + l.click() + self.assertEqual("Yes!", self.body_text()) + + def test_2(self): + """Test case 2""" + self.start('main') + l = self.xpath('li[2]/a') + l.click() + self.assertEqual("No!", self.body_text()) diff --git a/tests/bool.ur b/tests/bool.ur index b7e57dca..b8edbba6 100644 --- a/tests/bool.ur +++ b/tests/bool.ur @@ -1,8 +1,8 @@ -val page = fn b => <html><body> +val page = fn b => return <xml><body> {cdata (case b of False => "No!" | True => "Yes!")} -</body></html> +</body></xml> -val main : unit -> page = fn () => <html><body> +val main : unit -> transaction page = fn () => return <xml><body> <li><a link={page True}>True</a></li> <li><a link={page False}>False</a></li> -</body></html> +</body></xml> diff --git a/tests/both.py b/tests/both.py new file mode 100644 index 00000000..c3a8e8ee --- /dev/null +++ b/tests/both.py @@ -0,0 +1,12 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('Both/main') + t = self.xpath('form/input[@type=\'text\']') + t.send_keys('hello') + l = self.xpath('form/input[@type=\'submit\']') + l.click() + self.assertEqual("", self.body_text()) diff --git a/tests/both.ur b/tests/both.ur index d1c9f40e..b0f2a493 100644 --- a/tests/both.ur +++ b/tests/both.ur @@ -1,9 +1,10 @@ fun main () : transaction page = return <xml> <body> <form> - <textbox{#Text}/><submit action={submit}/> + <textbox{#Text}/> + <submit action={handler}/> </form> </body> </xml> -and submit r = return <xml/> +and handler r = return <xml/> diff --git a/tests/both.urs b/tests/both.urs new file mode 100644 index 00000000..6ac44e0b --- /dev/null +++ b/tests/both.urs @@ -0,0 +1 @@ +val main : unit -> transaction page diff --git a/tests/both2.py b/tests/both2.py new file mode 100644 index 00000000..b5b3c0fc --- /dev/null +++ b/tests/both2.py @@ -0,0 +1,12 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('Both2/main') + t = self.xpath('form/input[@type=\'text\']') + t.send_keys('hello') + l = self.xpath('form/input[@type=\'submit\']') + l.click() + self.assertEqual("", self.body_text()) diff --git a/tests/both2.ur b/tests/both2.ur index c3f25cc9..3190def8 100644 --- a/tests/both2.ur +++ b/tests/both2.ur @@ -1,14 +1,12 @@ fun main () : transaction page = let - fun submit r = return <xml/> + fun handler r = return <xml/> in return <xml> <body> <form> - <textbox{#Text}/><submit action={submit}/> + <textbox{#Text}/><submit action={handler}/> </form> </body> </xml> end - - diff --git a/tests/button.py b/tests/button.py new file mode 100644 index 00000000..14159fec --- /dev/null +++ b/tests/button.py @@ -0,0 +1,13 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('main') + b = self.xpath('button') + + b.click() + alert = self.driver.switch_to.alert + self.assertEqual("AHOY", alert.text) + alert.accept() diff --git a/tests/case.py b/tests/case.py new file mode 100644 index 00000000..611273e2 --- /dev/null +++ b/tests/case.py @@ -0,0 +1,15 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('main') + d = self.xpath('div') + txt = "zero is two: B\none is two: B\ntwo is two: A" + self.assertEqual(txt, d.text) + + b = self.xpath('button') + b.click() + alert = self.driver.switch_to.alert + self.assertEqual(txt, alert.text) diff --git a/tests/case.ur b/tests/case.ur index b131b27b..a6f4c700 100644 --- a/tests/case.ur +++ b/tests/case.ur @@ -11,6 +11,22 @@ datatype nat = O | S of nat val is_two = fn x : nat => case x of S (S O) => A | _ => B -val zero_is_two = is_two O -val one_is_two = is_two (S O) -val two_is_two = is_two (S (S O)) +val shw = fn x : t => + case x of A => "A" | B => "B" + +fun main (): transaction page = return <xml><body> + <div> + <p>zero is two: {[shw (is_two O)]}</p> + <p>one is two: {[shw (is_two (S O))]}</p> + <p>two is two: {[shw (is_two (S (S O)))]}</p> + </div> + + <button onclick={fn _ => let + val m = + "zero is two: " ^ shw (is_two O) ^ "\n" ^ + "one is two: " ^ shw (is_two (S O)) ^ "\n" ^ + "two is two: " ^ shw (is_two (S (S O))) + in + alert m + end}>click me</button> +</body></xml> diff --git a/tests/caseMod.py b/tests/caseMod.py new file mode 100644 index 00000000..16e49a5b --- /dev/null +++ b/tests/caseMod.py @@ -0,0 +1,25 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('main') + l1 = self.xpath('li[1]/a') + l1.click() + + self.assertEqual("C A\n\nAgain!", self.body_text()) + def test_2(self): + """Test case 2""" + self.start('main') + l1 = self.xpath('li[2]/a') + l1.click() + + self.assertEqual("C B\n\nAgain!", self.body_text()) + def test_3(self): + """Test case 3""" + self.start('main') + l1 = self.xpath('li[3]/a') + l1.click() + + self.assertEqual("D\n\nAgain!", self.body_text()) diff --git a/tests/caseMod.ur b/tests/caseMod.ur index 0a870160..15a7e07a 100644 --- a/tests/caseMod.ur +++ b/tests/caseMod.ur @@ -24,15 +24,15 @@ val toString = fn x => | C B => "C B" | D => "D" -val rec page = fn x => <html><body> +val rec page = fn x => return <xml><body> {cdata (toString x)}<br/> <br/> <a link={page x}>Again!</a> -</body></html> +</body></xml> -val main : unit -> page = fn () => <html><body> +val main : unit -> transaction page = fn () => return <xml><body> <li> <a link={page (C A)}>C A</a></li> <li> <a link={page (C B)}>C B</a></li> <li> <a link={page D}>D</a></li> -</body></html> +</body></xml> diff --git a/tests/ccheckbox.py b/tests/ccheckbox.py new file mode 100644 index 00000000..f2390368 --- /dev/null +++ b/tests/ccheckbox.py @@ -0,0 +1,15 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('main') + d = self.xpath('input') + p = self.xpath('span') + self.assertEqual("True 1", p.text) + d.click() + # the elements gets re-created from scratch + # so we must refresh our reference + p = self.xpath('span') + self.assertEqual("False 3", p.text) diff --git a/tests/ccheckbox.ur b/tests/ccheckbox.ur index 09a8ece9..d70c24a5 100644 --- a/tests/ccheckbox.ur +++ b/tests/ccheckbox.ur @@ -1,7 +1,7 @@ fun main () : transaction page = s <- source True; t <- source 1; - return <xml><body><ccheckbox source={s} onclick={set t 3}/> + return <xml><body><ccheckbox source={s} onclick={fn _ => set t 3}/> <dyn signal={s <- signal s; t <- signal t; return <xml>{[s]} {[t]}</xml>}/> diff --git a/tests/cdataF.py b/tests/cdataF.py new file mode 100644 index 00000000..8f43176f --- /dev/null +++ b/tests/cdataF.py @@ -0,0 +1,8 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('main') + self.assertEqual("<Hi.\nBye.", self.body_text()) diff --git a/tests/cdataF.ur b/tests/cdataF.ur index 3f8da45b..698dead7 100644 --- a/tests/cdataF.ur +++ b/tests/cdataF.ur @@ -1,8 +1,8 @@ -val snippet = fn s => <body> +val snippet = fn s => <xml> <h1>{cdata s}</h1> -</body> +</xml> -val main = fn () => <html><body> +val main : unit -> transaction page = fn () => return <xml><body> {snippet "<Hi."} {snippet "Bye."} -</body></html> +</body></xml> diff --git a/tests/cdataL.py b/tests/cdataL.py new file mode 100644 index 00000000..67ccd75e --- /dev/null +++ b/tests/cdataL.py @@ -0,0 +1,18 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('main') + l1 = self.xpath('li[1]/a') + l1.click() + + self.assertEqual("<Hi.", self.body_text()) + def test_2(self): + """Test case 2""" + self.start('main') + l1 = self.xpath('li[2]/a') + l1.click() + + self.assertEqual("Bye.", self.body_text()) diff --git a/tests/cdataL.ur b/tests/cdataL.ur index 3aa3bef6..42122b20 100644 --- a/tests/cdataL.ur +++ b/tests/cdataL.ur @@ -1,8 +1,8 @@ -val subpage = fn s => <html><body> +val subpage : string -> transaction page = fn s => return <xml><body> <h1>{cdata s}</h1> -</body></html> +</body></xml> -val main = fn () => <html><body> +val main : unit -> transaction page = fn () => return <xml><body> <li> <a link={subpage "<Hi."}>Door #1</a></li> <li> <a link={subpage "Bye."}>Door #2</a></li> -</body></html> +</body></xml> diff --git a/tests/cffi.py b/tests/cffi.py new file mode 100644 index 00000000..34b31b8c --- /dev/null +++ b/tests/cffi.py @@ -0,0 +1,37 @@ +import unittest +import base + +class Suite(base.Base): + def test_1(self): + """Test case 1""" + self.start('Cffi/main') + l1 = self.xpath('form[1]/input') + l1.click() + + b1 = self.xpath('button[1]') + b1.click() # TODO: check server output somehow + + b2 = self.xpath('button[2]') + b2.click() + alert = self.driver.switch_to.alert + self.assertEqual("<<Hoho>>", alert.text) + alert.accept() + + b3 = self.xpath('button[3]') + b3.click() + alert = self.driver.switch_to.alert + self.assertEqual("Hi there!", alert.text) + def test_2(self): + """Test case 2""" + self.start('Cffi/main') + l1 = self.xpath('form[2]/input') + l1.click() + + self.assertEqual("All good.", self.body_text()) + def test_3(self): + """Test case 3""" + self.start('Cffi/main') + l1 = self.xpath('form[3]/input') + l1.click() + + self.assertRegex(self.body_text(), "^Fatal error: .*$") diff --git a/tests/cffi.sh b/tests/cffi.sh new file mode 100755 index 00000000..1267c3e3 --- /dev/null +++ b/tests/cffi.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +CCOMP=gcc + +$CCOMP -pthread -Wimplicit -Werror -Wno-unused-value -I ..include/urweb -c "test.c" -o "test.o" -g +./driver.sh cffi diff --git a/tests/cffi.ur b/tests/cffi.ur index bcb9944c..89dc9906 100644 --- a/tests/cffi.ur +++ b/tests/cffi.ur @@ -3,9 +3,9 @@ fun printer () = Test.foo fun effect () = Test.print; return <xml><body> - <button value="Remote" onclick={printer ()}/> - <button value="Local" onclick={Test.bar "Hoho"}/> - <button value="Either" onclick={Test.print}/> + <button value="Remote" onclick={fn _ => rpc (printer ())}/> + <button value="Local" onclick={fn _ => Test.bar "Hoho"}/> + <button value="Either" onclick={fn _ => Test.print}/> </body></xml> fun xact () = diff --git a/tests/clib.urp b/tests/clib.urp index de89d03a..9ac0f144 100644 --- a/tests/clib.urp +++ b/tests/clib.urp @@ -1,6 +1,6 @@ ffi test include test.h -script http://localhost/test/test.js +jsFile test.js link test.o effectful Test.print serverOnly Test.foo diff --git a/tests/test.c b/tests/test.c index ef8558d7..24071aa6 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1,6 +1,6 @@ #include <stdio.h> -#include "../include/urweb.h" +#include "urweb/urweb.h" typedef uw_Basis_string uw_Test_t; @@ -27,16 +27,16 @@ uw_Basis_unit uw_Test_foo(uw_context ctx) { } static void commit(void *data) { - printf("Commit: %s\n", data); + printf("Commit: %s\n", (char*)data); } static void rollback(void *data) { - printf("Rollback: %s\n", data); + printf("Rollback: %s\n", (char*)data); } -static void free(void *data) { - printf("Free: %s\n", data); +static void ffree(void *data, int will_retry) { + printf("Free: %s, %d\n", (char*)data, will_retry); } uw_Basis_unit uw_Test_transactional(uw_context ctx) { - uw_register_transactional(ctx, "Beppo", commit, rollback, free); + uw_register_transactional(ctx, "Beppo", commit, rollback, ffree); return uw_unit_v; } diff --git a/tests/test.h b/tests/test.h index c0dec379..43a7746e 100644 --- a/tests/test.h +++ b/tests/test.h @@ -1,4 +1,4 @@ -#include "../include/urweb.h" +#include "urweb/urweb.h" typedef uw_Basis_string uw_Test_t; |