From 1a39672b01dc236068475e2d1a8a6f21814cba7e Mon Sep 17 00:00:00 2001 From: Artyom Shalkhakov Date: Sat, 22 Dec 2018 14:15:51 +0200 Subject: More tests. --- tests/Makefile | 13 ++++++++++++- tests/a_case_of_the_splits.py | 15 +++++++++++++++ tests/bodyClick.py | 18 ++++++++++++++++++ tests/bool.py | 17 +++++++++++++++++ tests/bool.ur | 8 ++++---- tests/both.py | 12 ++++++++++++ tests/both.ur | 5 +++-- tests/both.urs | 1 + tests/both2.py | 12 ++++++++++++ tests/both2.ur | 6 ++---- tests/button.py | 13 +++++++++++++ tests/case.py | 15 +++++++++++++++ tests/case.ur | 22 +++++++++++++++++++--- tests/caseMod.py | 25 +++++++++++++++++++++++++ tests/caseMod.ur | 8 ++++---- tests/ccheckbox.py | 15 +++++++++++++++ tests/ccheckbox.ur | 2 +- tests/cdataF.py | 8 ++++++++ tests/cdataF.ur | 8 ++++---- tests/cdataL.py | 18 ++++++++++++++++++ tests/cdataL.ur | 8 ++++---- tests/cffi.py | 37 +++++++++++++++++++++++++++++++++++++ tests/cffi.sh | 6 ++++++ tests/cffi.ur | 6 +++--- tests/clib.urp | 2 +- tests/test.c | 12 ++++++------ tests/test.h | 2 +- 27 files changed, 276 insertions(+), 38 deletions(-) create mode 100644 tests/a_case_of_the_splits.py create mode 100644 tests/bodyClick.py create mode 100644 tests/bool.py create mode 100644 tests/both.py create mode 100644 tests/both.urs create mode 100644 tests/both2.py create mode 100644 tests/button.py create mode 100644 tests/case.py create mode 100644 tests/caseMod.py create mode 100644 tests/ccheckbox.py create mode 100644 tests/cdataF.py create mode 100644 tests/cdataL.py create mode 100644 tests/cffi.py create mode 100755 tests/cffi.sh (limited to 'tests') 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 => +val page = fn b => return {cdata (case b of False => "No!" | True => "Yes!")} - + -val main : unit -> page = fn () => +val main : unit -> transaction page = fn () => return
  • True
  • False
  • - +
    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
    - + +
    -and submit r = return +and handler r = return 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 + fun handler r = return in return
    - +
    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 +
    +

    zero is two: {[shw (is_two O)]}

    +

    one is two: {[shw (is_two (S O))]}

    +

    two is two: {[shw (is_two (S (S O)))]}

    +
    + + +
    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 => +val rec page = fn x => return {cdata (toString x)}

    Again! - +
    -val main : unit -> page = fn () => +val main : unit -> transaction page = fn () => return
  • C A
  • C B
  • D
  • - +
    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 + return set t 3}/> {[s]} {[t]}}/> 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(" +val snippet = fn s =>

    {cdata s}

    - +
    -val main = fn () => +val main : unit -> transaction page = fn () => return {snippet " + 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(" +val subpage : string -> transaction page = fn s => return

    {cdata s}

    - +
    -val main = fn () => +val main : unit -> transaction page = fn () => return
  • Door #1
  • Door #2
  • - +
    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("<>", 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 -