]> gitweb.factorcode.org Git - factor.git/blob - extra/peg/javascript/javascript-tests.factor
Update actions, because Node.js 16 actions are deprecated, to Node.js 20
[factor.git] / extra / peg / javascript / javascript-tests.factor
1 ! Copyright (C) 2008 Chris Double.
2 ! See https://factorcode.org/license.txt for BSD license.
3
4 USING: accessors kernel math peg peg.ebnf peg.ebnf.private
5 peg.javascript peg.javascript.private sequences tools.test ;
6
7 {
8   V{
9     T{ ast-number f 123 }
10     ";"
11     T{ ast-string f "hello" }
12     ";"
13     T{ ast-name f "foo" }
14     "("
15     T{ ast-name f "x" }
16     ")"
17     ";"
18   }
19 } [
20   "123; 'hello'; foo(x);" tokenize-javascript
21 ] unit-test
22
23 { V{ T{ ast-regexp f "<(w+)[^>]*?)/>" "g" } } } [
24   "/<(\\w+)[^>]*?)\\/>/g" tokenize-javascript
25 ] unit-test
26
27 {
28     V{ T{ ast-string { value "abc\"def\"" } } }
29 } [ "\"abc\\\"def\\\"\"" tokenize-javascript ] unit-test
30
31 {
32     V{ T{ ast-string { value "\b\f\n\r\t\v'\"\\" } } }
33 } [ "\"\\b\\f\\n\\r\\t\\v\\'\\\"\\\\\"" tokenize-javascript ] unit-test
34
35 {
36     V{ T{ ast-string { value "abc" } } }
37 } [ "\"\\x61\\u0062\\u{63}\"" tokenize-javascript ] unit-test
38
39 {
40   T{
41       ast-begin
42       f
43       V{
44           T{ ast-number f 123 }
45           T{ ast-string f "hello" }
46           T{
47               ast-call
48               f
49               T{ ast-get f "foo" }
50               V{ T{ ast-get f "x" } }
51           }
52       }
53   }
54 } [
55   "123; 'hello'; foo(x);" parse-javascript
56 ] unit-test
57
58 { t } [
59 "
60 var x=5
61 var y=10
62 " main \ parse-javascript rule (parse) remaining>> length zero?
63 ] unit-test
64
65
66 { t } [
67 "
68 function foldl(f, initial, seq) {
69    for(var i=0; i< seq.length; ++i)
70      initial = f(initial, seq[i]);
71    return initial;
72 }" main \ parse-javascript rule (parse) remaining>> length zero?
73 ] unit-test
74
75 { t } [
76 "
77 ParseState.prototype.from = function(index) {
78     var r = new ParseState(this.input, this.index + index);
79     r.cache = this.cache;
80     r.length = this.length - index;
81     return r;
82 }" main \ parse-javascript rule (parse) remaining>> length zero?
83 ] unit-test
84
85
86 { T{ ast-begin f V{ T{ ast-number f 123 } } } } [
87   "123;" parse-javascript
88 ] unit-test