Browse Source

Added unit tests

Chris Konstad 4 years ago
parent
commit
006e43a4f4

+ 1 - 0
.merlin

@ -16,3 +16,4 @@ B _build/src
16 16
PKG yojson
17 17
PKG batteries
18 18
PKG core
19
PKG oUnit

+ 13 - 0
_oasis

@ -61,3 +61,16 @@ Executable "markright_exec"
61 61
    core,
62 62
    markright,
63 63
    threads
64

													
65
# +----------------------------------------------------------------------------+
66
# | Tests                                                                      |
67
# +----------------------------------------------------------------------------+
68
Executable test
69
  Install: false
70
  Path: .
71
  MainIs: test.ml
72
  BuildDepends: oUnit, markright
73

													
74
Test "main"
75
  Type: Custom (0.0.1)
76
  Command: $test

+ 0 - 1
lib/parser.ml

@ -38,7 +38,6 @@ let rec parse text =
38 38
      let contents = String.trim (String.sub name
39 39
                     (String.length var_start_string)
40 40
                     name_length) in
41
      print_endline contents;
42 41
      if '{' = contents.[0] then
43 42
        Config(contents)::next
44 43
      else

+ 50 - 0
test.ml

@ -0,0 +1,50 @@
1
open Markright
2
open OUnit2
3

													
4
(* Test basic functionality *)
5
let test_basic test_ctxt = assert_equal
6
    "I like OCaml!"
7
    (markright
8
       false
9
       "{{ {\"mappings\": { \"lang\": \"OCaml\"} } }}I like {{lang}}!"
10
       "./test")
11

													
12
let test_basic_escaped test_ctxt = assert_equal
13
    "I like \{{lang}}!"
14
    (markright
15
       false
16
       "{{ {\"mappings\": { \"lang\": \"OCaml\"} } }}I like \{{lang}}!"
17
       "./test")
18

													
19
let test_basic_nested text_ctxt = assert_equal
20
    (load_file "test/test1.md")
21
    (markright false (load_file "test/test1.mr") "./test")
22

													
23
(* Test imports *)
24
let test_import_nested text_ctxt = assert_equal
25
    (load_file "test/test2.md")
26
    (markright false (load_file "test/test2.mr") "./test")
27

													
28
(* Test error on multiple defs *)
29
let test_mult_error text_ctxt = assert_raises
30
    (Mapper.Multiple_def("fruit"))
31
    (fun () -> (markright false (load_file "test/test3.mr") "./test"))
32

													
33
(* Test ignoring error on multiple defs *)
34
let test_mult_ignore text_ctxt = assert_equal
35
    (load_file "test/test3.md")
36
    (markright true (load_file "test/test3.mr") "./test")
37

													
38
let suite =
39
  "suite">:::
40
  [
41
    "test_basic">:: test_basic;
42
    "test_basic_escaped">:: test_basic_escaped;
43
    "test_basic_nested">:: test_basic_nested;
44
    "test_import_nested">:: test_import_nested;
45
    "test_mult_error">:: test_mult_error;
46
    "test_mult_ignore">:: test_mult_ignore;
47
  ]
48

													
49
let () =
50
  run_test_tt_main suite

test/empty.json → test/legacy/empty.json


test/test.json → test/legacy/test.json


+ 7 - 0
test/legacy/test2.json

@ -0,0 +1,7 @@
1
{
2
  "girlfriend": "Kasey",
3
  "parents": {
4
    "mom": "Andrea",
5
    "dad": "Rolf"
6
  }
7
}

+ 13 - 0
test/legacy/test2.mr

@ -0,0 +1,13 @@
1
{{
2
{
3
  "mappings": {
4
    "roommate": "kuecks"
5
  },
6
  "imports": [
7
    "test.json"
8
  ]
9
}
10
}}
11

													
12
My girlfriend is {{girlfriend}}.  My roommate is {{roommate}}.  My parents are
13
{{parents.dad}} and {{parents.mom}}.

test/test21.json → test/legacy/test21.json


test/test22.json → test/legacy/test22.json


test/test23.json → test/legacy/test23.json


+ 13 - 0
test/legacy/test3.mr

@ -0,0 +1,13 @@
1
{{
2
{
3
  "imports": [
4
    "test21.json", "test22.json"
5
  ],
6
  "mappings": {
7
    "roommate": "kuecks"
8
  }
9
}
10
}}
11

													
12
My girlfriend is {{girlfriend}}.  My roommate is {{roommate}}.  My parents are
13
{{parents.dad}} and {{parents.mom}}.

test/test4.mr → test/legacy/test4.mr


+ 2 - 0
test/test1.md

@ -0,0 +1,2 @@
1

													
2
I like apple pie with vanilla ice cream.

+ 11 - 0
test/test1.mr

@ -0,0 +1,11 @@
1
{{
2
{
3
  "mappings": {
4
    "fruit": "apple",
5
    "desserts" : {
6
      "ice_cream": "vanilla"
7
    }
8
  }
9
}
10
}}
11
I like {{fruit}} pie with {{desserts.ice_cream}} ice cream.

+ 2 - 4
test/test2.json

@ -1,7 +1,5 @@
1 1
{
2
  "girlfriend": "Kasey",
3
  "parents": {
4
    "mom": "Andrea",
5
    "dad": "Rolf"
2
  "mappings": {
3
    "fruit": "apple"
6 4
  }
7 5
}

+ 2 - 0
test/test2.md

@ -0,0 +1,2 @@
1

													
2
I like apple pie with vanilla ice cream.

+ 8 - 8
test/test2.mr

@ -1,13 +1,13 @@
1 1
{{
2 2
{
3
  "mappings": {
4
    "roommate": "kuecks"
5
  },
6 3
  "imports": [
7
    "test.json"
8
  ]
4
    "test2.json"
5
  ],
6
  "mappings": {
7
    "desserts" : {
8
      "ice_cream": "vanilla"
9
    }
10
  }
9 11
}
10 12
}}
11

													
12
My girlfriend is {{girlfriend}}.  My roommate is {{roommate}}.  My parents are
13
{{parents.dad}} and {{parents.mom}}.
13
I like {{fruit}} pie with {{desserts.ice_cream}} ice cream.

+ 5 - 0
test/test3.json

@ -0,0 +1,5 @@
1
{
2
  "mappings": {
3
    "fruit": "apple"
4
  }
5
}

+ 2 - 0
test/test3.md

@ -0,0 +1,2 @@
1

													
2
I like apple pie with vanilla ice cream.

+ 6 - 5
test/test3.mr

@ -1,13 +1,14 @@
1 1
{{
2 2
{
3 3
  "imports": [
4
    "test21.json", "test22.json"
4
    "test3.json"
5 5
  ],
6 6
  "mappings": {
7
    "roommate": "kuecks"
7
    "fruit": "apple",
8
    "desserts" : {
9
      "ice_cream": "vanilla"
10
    }
8 11
  }
9 12
}
10 13
}}
11

													
12
My girlfriend is {{girlfriend}}.  My roommate is {{roommate}}.  My parents are
13
{{parents.dad}} and {{parents.mom}}.
14
I like {{fruit}} pie with {{desserts.ice_cream}} ice cream.