Check-in [fd28ccab7a]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[5661b375d3] Added tests for ParserAction handling on the and and or combinators. Wrote passing tests for them as well.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:fd28ccab7a3c19ee87e22d16556a5f8445d8bb88
User & Date: User 2016-10-27 19:08:38
Context
2016-10-27
19:30
[02a0006c55] Added exact combinator and matching tests. check-in: b2b4e7c3c2 user: User tags: trunk
19:08
[5661b375d3] Added tests for ParserAction handling on the and and or combinators. Wrote passing tests for them as well. check-in: fd28ccab7a user: User tags: trunk
19:06
Changed the code for running tests to make thhe output more concise. check-in: a6ce9aa409 user: User tags: trunk
Changes

Changes to src/pcomb.ts.

105
106
107
108
109
110
111


112
113
114
115
116
117
118
119
120
121
122
123
124
            } else {
                tryInput = tryParseResult[1];
                tryOutput = tryParseResult[2];
            }
        }

        if (result[0]) { // All parsers finished successfully.


            if (outerAction) {
                result[2] = outerAction(lastMatched(result[2]), result[2]);
            }

            result[1] = tryInput;
            result[2] = tryOutput;
        }

        return result;
    };
}

/** Execute the given parser until it fails; return all matched characters as a single match. */







>
>




|
<







105
106
107
108
109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
            } else {
                tryInput = tryParseResult[1];
                tryOutput = tryParseResult[2];
            }
        }

        if (result[0]) { // All parsers finished successfully.
            result[1] = tryInput;
            result[2] = tryOutput;
            if (outerAction) {
                result[2] = outerAction(lastMatched(result[2]), result[2]);
            }



        }

        return result;
    };
}

/** Execute the given parser until it fails; return all matched characters as a single match. */

Changes to tests/test.ts.

55
56
57
58
59
60
61

62
63
64
65
66
67
68
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
114
115
116
117
118
119
120







121
122
123
124
125
126
127
...
141
142
143
144
145
146
147

148
149
150
151
152
153

154
155
156
157

158
159
160
161
162
163

164
165
166
167

168
169
170
171
172
173

174
175
176
177
178
179
180
    private anyParser2: pcomb.Parser;
    private numericParser: pcomb.Parser;
    private numericSequence: pcomb.Parser;
    private storeNameValue: (matched: string, output: TestOutput) => TestOutput;
    private recordWhitespace: (matched: string, output: TestOutput) => TestOutput;
    private dumbGrabber: (matched: string, output: TestOutput) => TestOutput;
    private nameTranslator: (matched: string, output: TestOutput) => TestOutput;


    constructor() {
        super();
        this.parsers = new pcomb.ParserSet(this.input.copy(), this.output.copy());
    }

    setUp() {
................................................................................
        this.litValue = pcomb.lit("value");
        this.litValueOther = pcomb.lit("othervalue");
        this.litColon = pcomb.lit(":");
        this.litSemicolon = pcomb.lit(";");
        this.litSpace = pcomb.lit(" ");
        this.optWsParser = pcomb.opt(this.litSpace);
        this.allStoreName = pcomb.any(null, this.storeNameValue);
        this.nameValuePair = pcomb.and([this.litName, this.litColon, this.litValue]);
        this.eitherNameValuePair = pcomb.or([this.litValue, this.litValueOther]);
        this.nameValuePair2 = pcomb.and([this.litName, this.litColon, this.eitherNameValuePair]);
        this.optParser = pcomb.and([
            this.litName, this.optWsParser, this.litColon,
            this.optWsParser, this.litValue]);
        this.anyParser1 = pcomb.and([this.litName, this.litColon, this.allStoreName]);
        this.anyParser2 = pcomb.and([this.litName, this.litColon, pcomb.any(this.litSemicolon), this.litSemicolon]);
        this.numericParser = pcomb.numeric();
................................................................................
                newOutput.name = "Adam C";
            } else {
                newOutput.name = matched;
            }

            return newOutput;
        };







    }

    litTest1() {
        let tryResult = this.parsers.parse(this.litName, "name");

        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 1);
................................................................................

        this.isFalse(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 0);
    }

    andTest1() {
        let tryResult = this.parsers.parse(this.nameValuePair, "name:value");


        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 3);
        this.areIdentical(tryResult[2].matched[0], "name");
        this.areIdentical(tryResult[2].matched[1], ":");
        this.areIdentical(tryResult[2].matched[2], "value");

    }

    orTest1() {
        let tryResult = this.parsers.parse(this.nameValuePair2, "name:value");


        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 3);
        this.areIdentical(tryResult[2].matched[0], "name");
        this.areIdentical(tryResult[2].matched[1], ":");
        this.areIdentical(tryResult[2].matched[2], "value");

    }

    orTest2() {
        let tryResult = this.parsers.parse(this.nameValuePair2, "name:othervalue");


        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 3);
        this.areIdentical(tryResult[2].matched[0], "name");
        this.areIdentical(tryResult[2].matched[1], ":");
        this.areIdentical(tryResult[2].matched[2], "othervalue");

    }

    optTest() {
        let tryResult1 = this.parsers.parse(this.optParser, "name:value");
        this.isTrue(tryResult1[0]);
        this.areIdentical(tryResult1[2].matched.length, 3);
        this.areIdentical(tryResult1[2].matched[0], "name");







>







 







|
|







 







>
>
>
>
>
>
>







 







>






>




>






>
|
<
<
|
>






>







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
    private anyParser2: pcomb.Parser;
    private numericParser: pcomb.Parser;
    private numericSequence: pcomb.Parser;
    private storeNameValue: (matched: string, output: TestOutput) => TestOutput;
    private recordWhitespace: (matched: string, output: TestOutput) => TestOutput;
    private dumbGrabber: (matched: string, output: TestOutput) => TestOutput;
    private nameTranslator: (matched: string, output: TestOutput) => TestOutput;
    private lastMatchIsName: (matched: string, output: TestOutput) => TestOutput;

    constructor() {
        super();
        this.parsers = new pcomb.ParserSet(this.input.copy(), this.output.copy());
    }

    setUp() {
................................................................................
        this.litValue = pcomb.lit("value");
        this.litValueOther = pcomb.lit("othervalue");
        this.litColon = pcomb.lit(":");
        this.litSemicolon = pcomb.lit(";");
        this.litSpace = pcomb.lit(" ");
        this.optWsParser = pcomb.opt(this.litSpace);
        this.allStoreName = pcomb.any(null, this.storeNameValue);
        this.nameValuePair = pcomb.and([this.litName, this.litColon, this.litValue], this.lastMatchIsName);
        this.eitherNameValuePair = pcomb.or([this.litValue, this.litValueOther], this.dumbGrabber);
        this.nameValuePair2 = pcomb.and([this.litName, this.litColon, this.eitherNameValuePair]);
        this.optParser = pcomb.and([
            this.litName, this.optWsParser, this.litColon,
            this.optWsParser, this.litValue]);
        this.anyParser1 = pcomb.and([this.litName, this.litColon, this.allStoreName]);
        this.anyParser2 = pcomb.and([this.litName, this.litColon, pcomb.any(this.litSemicolon), this.litSemicolon]);
        this.numericParser = pcomb.numeric();
................................................................................
                newOutput.name = "Adam C";
            } else {
                newOutput.name = matched;
            }

            return newOutput;
        };

        this.lastMatchIsName = function(matched: string, output: TestOutput): TestOutput {
            let newOutput = output.copy();
            newOutput.name = output.matched[output.matched.length - 1];

            return newOutput;
        };
    }

    litTest1() {
        let tryResult = this.parsers.parse(this.litName, "name");

        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 1);
................................................................................

        this.isFalse(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 0);
    }

    andTest1() {
        let tryResult = this.parsers.parse(this.nameValuePair, "name:value");
        let resultAsTest: TestOutput = <TestOutput> tryResult[2];

        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 3);
        this.areIdentical(tryResult[2].matched[0], "name");
        this.areIdentical(tryResult[2].matched[1], ":");
        this.areIdentical(tryResult[2].matched[2], "value");
        this.areIdentical(resultAsTest.name, "value");
    }

    orTest1() {
        let tryResult = this.parsers.parse(this.nameValuePair2, "name:value");
        let resultAsTest: TestOutput = <TestOutput> tryResult[2];

        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 3);
        this.areIdentical(tryResult[2].matched[0], "name");
        this.areIdentical(tryResult[2].matched[1], ":");
        this.areIdentical(tryResult[2].matched[2], "value");
        this.areIdentical(resultAsTest.name, "value");



        tryResult = this.parsers.parse(this.nameValuePair2, "name:othervalue");
        resultAsTest = <TestOutput> tryResult[2];

        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[2].matched.length, 3);
        this.areIdentical(tryResult[2].matched[0], "name");
        this.areIdentical(tryResult[2].matched[1], ":");
        this.areIdentical(tryResult[2].matched[2], "othervalue");
        this.areIdentical(resultAsTest.name, "othervalue");
    }

    optTest() {
        let tryResult1 = this.parsers.parse(this.optParser, "name:value");
        this.isTrue(tryResult1[0]);
        this.areIdentical(tryResult1[2].matched.length, 3);
        this.areIdentical(tryResult1[2].matched[0], "name");