From ba8cf26e55e12a87719e933b6769ba380f80a28a Mon Sep 17 00:00:00 2001 From: Nicolas Zozol Date: Sun, 15 Oct 2017 21:47:40 +0200 Subject: [PATCH] #92: Renaming stream to Streams. Tests ok inside the lib. No integration test yet done. --- src/lib/index.js | 6 +- src/lib/standard/markdown/document-parser.js | 4 +- src/test/parsec/chars-bundle-test.js | 136 +++++++++---------- src/test/parsec/flow-bundle-test.js | 6 +- src/test/standard/token-test.js | 6 +- 5 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/lib/index.js b/src/lib/index.js index 675ee56..d75756d 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -12,7 +12,7 @@ import parsec from './parsec/index'; import parser from './parsec/parser'; import {F, C, N} from './parsec/index'; import standard from './standard/index'; -import Stream from './stream/index'; +import Streams from './stream/index'; const JSON = standard.jsonParser; const MD = standard.markdownBundle; @@ -24,7 +24,7 @@ export const bundle = { genlex, parsec, standard, - Stream, + Streams, parser, F, C, @@ -40,7 +40,7 @@ export { genlex, parsec, standard, - Stream, + Streams, parser, F, C, diff --git a/src/lib/standard/markdown/document-parser.js b/src/lib/standard/markdown/document-parser.js index 039853c..25e203e 100644 --- a/src/lib/standard/markdown/document-parser.js +++ b/src/lib/standard/markdown/document-parser.js @@ -2,14 +2,14 @@ * Created by Simon on 15/12/2016. */ /* -import Stream from '../../stream/index'; +import Streams from '../../stream/index'; function parseDocument( string, offset=0){ - return document().parse(Stream.ofString(string), offset) + return document().parse(Streams.ofString(string), offset) } diff --git a/src/test/parsec/chars-bundle-test.js b/src/test/parsec/chars-bundle-test.js index 3796bea..596e343 100644 --- a/src/test/parsec/chars-bundle-test.js +++ b/src/test/parsec/chars-bundle-test.js @@ -1,11 +1,11 @@ -import stream from '../../lib/stream/index'; +import Streams from '../../lib/stream/index'; import {F, C} from '../../lib/parsec/index'; let value = undefined; function testParser(parser, string) { - let myStream = stream.ofString(string); - let parsing = parser.parse(myStream); + let stream = Streams.ofString(string); + let parsing = parser.parse(stream); value = parsing.value; } @@ -19,7 +19,7 @@ export default { test.expect(1); // tests here test.equal( - C.char('a').parse(stream.ofString('a'), 0).isAccepted(), + C.char('a').parse(Streams.ofString('a'), 0).isAccepted(), true, 'should be accepted.' ); @@ -30,7 +30,7 @@ export default { test.expect(1); // tests here test.equal( - C.char('a').parse(stream.ofString('b'), 0).isAccepted(), + C.char('a').parse(Streams.ofString('b'), 0).isAccepted(), false, 'should be rejected.' ); @@ -50,7 +50,7 @@ export default { test.expect(1); // tests here test.equal( - C.notChar('a').parse(stream.ofString('b'), 0).isAccepted(), + C.notChar('a').parse(Streams.ofString('b'), 0).isAccepted(), true, 'should be accepted.' ); @@ -61,7 +61,7 @@ export default { test.expect(1); // tests here test.equal( - C.notChar('a').parse(stream.ofString('a'), 0).isAccepted(), + C.notChar('a').parse(Streams.ofString('a'), 0).isAccepted(), false, 'should be rejected.' ); @@ -81,7 +81,7 @@ export default { test.expect(1); // tests here test.equal( - C.charNotIn('a').parse(stream.ofString('b'), 0).isAccepted(), + C.charNotIn('a').parse(Streams.ofString('b'), 0).isAccepted(), true, 'should be accepted.' ); @@ -92,7 +92,7 @@ export default { test.expect(1); // tests here test.equal( - C.charNotIn('a').parse(stream.ofString('a'), 0).isAccepted(), + C.charNotIn('a').parse(Streams.ofString('a'), 0).isAccepted(), false, 'should be rejected.' ); @@ -103,7 +103,7 @@ export default { test.expect(1); // tests here test.equal( - C.charIn('a').parse(stream.ofString('a'), 0).isAccepted(), + C.charIn('a').parse(Streams.ofString('a'), 0).isAccepted(), true, 'should be accepted.' ); @@ -114,7 +114,7 @@ export default { test.expect(1); // tests here test.equal( - C.charIn('a').parse(stream.ofString('b'), 0).isAccepted(), + C.charIn('a').parse(Streams.ofString('b'), 0).isAccepted(), false, 'should be rejected.' ); @@ -126,7 +126,7 @@ export default { test.expect(1); // tests here test.equal( - C.lowerCase.parse(stream.ofString('a'), 0).isAccepted(), + C.lowerCase.parse(Streams.ofString('a'), 0).isAccepted(), true, 'should be accepted.' ); @@ -137,7 +137,7 @@ export default { test.expect(1); // tests here test.equal( - C.lowerCase.parse(stream.ofString('A'), 0).isAccepted(), + C.lowerCase.parse(Streams.ofString('A'), 0).isAccepted(), false, 'should be rejected.' ); @@ -148,7 +148,7 @@ export default { test.expect(1); // tests here test.equal( - C.upperCase.parse(stream.ofString('A'), 0).isAccepted(), + C.upperCase.parse(Streams.ofString('A'), 0).isAccepted(), true, 'should be accepted.' ); @@ -159,7 +159,7 @@ export default { test.expect(1); // tests here test.equal( - C.upperCase.parse(stream.ofString('z'), 0).isAccepted(), + C.upperCase.parse(Streams.ofString('z'), 0).isAccepted(), false, 'should be rejected.' ); @@ -170,7 +170,7 @@ export default { test.expect(1); // tests here test.equal( - C.letter.parse(stream.ofString('A'), 0).isAccepted(), + C.letter.parse(Streams.ofString('A'), 0).isAccepted(), true, 'should be accepted.' ); @@ -181,7 +181,7 @@ export default { test.expect(1); // tests here test.equal( - C.letter.parse(stream.ofString('z'), 0).isAccepted(), + C.letter.parse(Streams.ofString('z'), 0).isAccepted(), true, 'should be accepted.' ); @@ -191,7 +191,7 @@ export default { test.expect(1); // tests here test.equal( - C.letter.parse(stream.ofString(' '), 0).isAccepted(), + C.letter.parse(Streams.ofString(' '), 0).isAccepted(), false, 'should be rejected.' ); @@ -202,7 +202,7 @@ export default { test.expect(1); // tests here test.equal( - C.letter.parse(stream.ofString('0'), 0).isAccepted(), + C.letter.parse(Streams.ofString('0'), 0).isAccepted(), false, 'should be rejected.' ); @@ -211,56 +211,56 @@ export default { 'expect occidental letter to be accepted': function (test) { - test.ok(C.letter.parse(stream.ofString('a'), 0).isAccepted()); - test.ok(C.letterAs().parse(stream.ofString('a'), 0).isAccepted()); - test.ok(C.letterAs(C.OCCIDENTAL_LETTER).parse(stream.ofString('a')).isAccepted()); - test.ok(C.letterAs(C.OCCIDENTAL_LETTER).parse(stream.ofString('é')).isAccepted()); - test.ok(!C.letterAs(C.OCCIDENTAL_LETTER).parse(stream.ofString('Б')).isAccepted()); - test.ok(!C.letterAs(C.OCCIDENTAL_LETTER).parse(stream.ofString('÷')).isAccepted()); + test.ok(C.letter.parse(Streams.ofString('a'), 0).isAccepted()); + test.ok(C.letterAs().parse(Streams.ofString('a'), 0).isAccepted()); + test.ok(C.letterAs(C.OCCIDENTAL_LETTER).parse(Streams.ofString('a')).isAccepted()); + test.ok(C.letterAs(C.OCCIDENTAL_LETTER).parse(Streams.ofString('é')).isAccepted()); + test.ok(!C.letterAs(C.OCCIDENTAL_LETTER).parse(Streams.ofString('Б')).isAccepted()); + test.ok(!C.letterAs(C.OCCIDENTAL_LETTER).parse(Streams.ofString('÷')).isAccepted()); test.done(); }, 'expect occidental letters to be accepted': function (test) { - test.ok(C.letters.then(F.eos).parse(stream.ofString('aéÉ'), 0).isAccepted()); - test.ok(C.lettersAs().then(F.eos).parse(stream.ofString('aéÉ'), 0).isAccepted()); - test.ok(C.lettersAs(C.OCCIDENTAL_LETTER).parse(stream.ofString('a')).isAccepted()); - test.ok(C.lettersAs(C.OCCIDENTAL_LETTER).then(F.eos).parse(stream.ofString('éA')).isAccepted()); - test.ok(!C.lettersAs(C.OCCIDENTAL_LETTER).then(F.eos).parse(stream.ofString('БAs')).isAccepted()); + test.ok(C.letters.then(F.eos).parse(Streams.ofString('aéÉ'), 0).isAccepted()); + test.ok(C.lettersAs().then(F.eos).parse(Streams.ofString('aéÉ'), 0).isAccepted()); + test.ok(C.lettersAs(C.OCCIDENTAL_LETTER).parse(Streams.ofString('a')).isAccepted()); + test.ok(C.lettersAs(C.OCCIDENTAL_LETTER).then(F.eos).parse(Streams.ofString('éA')).isAccepted()); + test.ok(!C.lettersAs(C.OCCIDENTAL_LETTER).then(F.eos).parse(Streams.ofString('БAs')).isAccepted()); test.done(); }, 'expect ascii letter to be accepted': function (test) { - test.ok(C.letterAs(C.ASCII_LETTER).parse(stream.ofString('a'), 0).isAccepted()); - test.ok(!C.letterAs(C.ASCII_LETTER).parse(stream.ofString('é')).isAccepted()); - test.ok(!C.letterAs(C.ASCII_LETTER).parse(stream.ofString('Б')).isAccepted()); + test.ok(C.letterAs(C.ASCII_LETTER).parse(Streams.ofString('a'), 0).isAccepted()); + test.ok(!C.letterAs(C.ASCII_LETTER).parse(Streams.ofString('é')).isAccepted()); + test.ok(!C.letterAs(C.ASCII_LETTER).parse(Streams.ofString('Б')).isAccepted()); test.done(); }, 'expect ascii letters to be accepted': function (test) { - test.ok(C.lettersAs(C.ASCII_LETTER).then(F.eos).parse(stream.ofString('a')).isAccepted()); - test.ok(!C.lettersAs(C.ASCII_LETTER).then(F.eos).parse(stream.ofString('éA')).isAccepted()); - test.ok(!C.lettersAs(C.ASCII_LETTER).then(F.eos).parse(stream.ofString('БAs')).isAccepted()); + test.ok(C.lettersAs(C.ASCII_LETTER).then(F.eos).parse(Streams.ofString('a')).isAccepted()); + test.ok(!C.lettersAs(C.ASCII_LETTER).then(F.eos).parse(Streams.ofString('éA')).isAccepted()); + test.ok(!C.lettersAs(C.ASCII_LETTER).then(F.eos).parse(Streams.ofString('БAs')).isAccepted()); test.done(); }, 'expect utf8 letter to be accepted': function (test) { - test.ok(C.letterAs(C.UTF8_LETTER).parse(stream.ofString('a')).isAccepted()); - test.ok(C.letterAs(C.UTF8_LETTER).parse(stream.ofString('é')).isAccepted()); - test.ok(C.letterAs(C.UTF8_LETTER).parse(stream.ofString('Б')).isAccepted()); - test.ok(!C.letterAs(C.UTF8_LETTER).parse(stream.ofString('÷')).isAccepted()); + test.ok(C.letterAs(C.UTF8_LETTER).parse(Streams.ofString('a')).isAccepted()); + test.ok(C.letterAs(C.UTF8_LETTER).parse(Streams.ofString('é')).isAccepted()); + test.ok(C.letterAs(C.UTF8_LETTER).parse(Streams.ofString('Б')).isAccepted()); + test.ok(!C.letterAs(C.UTF8_LETTER).parse(Streams.ofString('÷')).isAccepted()); test.done(); }, 'expect utf8 letters to be accepted': function (test) { - test.ok(C.lettersAs(C.UTF8_LETTER).then(F.eos).parse(stream.ofString('a')).isAccepted()); - test.ok(C.lettersAs(C.UTF8_LETTER).then(F.eos).parse(stream.ofString('éA')).isAccepted()); - test.ok(C.lettersAs(C.UTF8_LETTER).then(F.eos).parse(stream.ofString('БAs')).isAccepted()); - test.ok(!C.letterAs(C.UTF8_LETTER).then(F.eos).parse(stream.ofString('Б÷As')).isAccepted()); + test.ok(C.lettersAs(C.UTF8_LETTER).then(F.eos).parse(Streams.ofString('a')).isAccepted()); + test.ok(C.lettersAs(C.UTF8_LETTER).then(F.eos).parse(Streams.ofString('éA')).isAccepted()); + test.ok(C.lettersAs(C.UTF8_LETTER).then(F.eos).parse(Streams.ofString('БAs')).isAccepted()); + test.ok(!C.letterAs(C.UTF8_LETTER).then(F.eos).parse(Streams.ofString('Б÷As')).isAccepted()); test.done(); }, @@ -270,7 +270,7 @@ export default { // tests here const parsing = C.letters .thenLeft(F.eos) - .parse(stream.ofString('someLetters'), 0); + .parse(Streams.ofString('someLetters'), 0); test.equal(parsing.isAccepted(), true, 'should be accepted.'); test.deepEqual(parsing.value, 'someLetters', 'should be equal.'); test.done(); @@ -281,7 +281,7 @@ export default { // tests here const parsing = C.letters .then(F.eos) - .parse(stream.ofString('some Letters'), 0); + .parse(Streams.ofString('some Letters'), 0); test.equal(parsing.isAccepted(), false, 'should be rejected.'); test.notDeepEqual(parsing.value, 'some Letters', 'should be equal.'); test.done(); @@ -292,7 +292,7 @@ export default { // tests here const parsing = C.letters .then(F.eos) - .parse(stream.ofString('some2Letters'), 0); + .parse(Streams.ofString('some2Letters'), 0); test.equal(parsing.isAccepted(), false, 'should be accepted.'); test.done(); }, @@ -302,7 +302,7 @@ export default { // tests here const parsing = C.letters .thenLeft(F.eos) - .parse(stream.ofString('someLetters'), 0); + .parse(Streams.ofString('someLetters'), 0); test.equal(parsing.value, 'someLetters', 'not a string'); test.done(); }, @@ -312,7 +312,7 @@ export default { test.expect(1); // tests here test.equal( - C.string('Hello').parse(stream.ofString('Hello'), 0).isAccepted(), + C.string('Hello').parse(Streams.ofString('Hello'), 0).isAccepted(), true, 'should be accepted.' ); @@ -323,7 +323,7 @@ export default { test.expect(1); // tests here test.equal( - C.string('hello').parse(stream.ofString('hell'), 0).isAccepted(), + C.string('hello').parse(Streams.ofString('hell'), 0).isAccepted(), false, 'should be rejected.' ); @@ -331,7 +331,7 @@ export default { }, 'test stringIn': function(test) { - let line = stream.ofString('James Bond'); + let line = Streams.ofString('James Bond'); const combinator = C.stringIn(['The', 'James', 'Bond', 'series']); const value = combinator.parse(line).value; @@ -342,7 +342,7 @@ export default { 'test stringIn Similar': function(test) { // Checks the search comes back after each search - let line = stream.ofString('Jack James Jane'); + let line = Streams.ofString('Jack James Jane'); const combinator = C.stringIn(['Jamie', 'Jacko', 'Jack']); const parsing = combinator.parse(line); @@ -354,7 +354,7 @@ export default { }, 'test stringIn one string sidecase': function(test) { - let line = stream.ofString('James'); + let line = Streams.ofString('James'); const combinator = C.stringIn(['James']); const value = combinator.parse(line).value; @@ -364,7 +364,7 @@ export default { }, 'test stringIn empty sidecase': function(test) { - let line = stream.ofString('James'); + let line = Streams.ofString('James'); const combinator = C.stringIn([]).then(F.eos); const parsing = combinator.parse(line); @@ -373,7 +373,7 @@ export default { }, 'test stringIn empty accept nothing sidecase': function(test) { - let line = stream.ofString(''); + let line = Streams.ofString(''); const combinator = C.stringIn([]).then(F.eos); const parsing = combinator.parse(line); @@ -385,7 +385,7 @@ export default { test.expect(1); // tests here test.equal( - C.notString('**').parse(stream.ofString('hello'), 0).isAccepted(), + C.notString('**').parse(Streams.ofString('hello'), 0).isAccepted(), true, 'should be accepted.' ); @@ -396,7 +396,7 @@ export default { test.expect(1); // tests here test.equal( - C.notString('**').parse(stream.ofString('hello'), 0).value, + C.notString('**').parse(Streams.ofString('hello'), 0).value, 'h', 'should be h.' ); @@ -407,7 +407,7 @@ export default { test.expect(1); // tests here test.equal( - C.notString('**').parse(stream.ofString('**hello'), 0).isAccepted(), + C.notString('**').parse(Streams.ofString('**hello'), 0).isAccepted(), false, 'should be rejected.' ); @@ -419,7 +419,7 @@ export default { test.expect(1); // tests here test.equal( - C.utf8Letter.parse(stream.ofString('é'), 0).isAccepted(), + C.utf8Letter.parse(Streams.ofString('é'), 0).isAccepted(), true, 'should be accepted.' ); @@ -431,12 +431,12 @@ export default { //Белград //български test.equal( - C.utf8Letter.parse(stream.ofString('Б'), 0).isAccepted(), + C.utf8Letter.parse(Streams.ofString('Б'), 0).isAccepted(), true, 'should be accepted.' ); test.equal( - C.utf8Letter.parse(stream.ofString('б'), 0).isAccepted(), + C.utf8Letter.parse(Streams.ofString('б'), 0).isAccepted(), true, 'should be accepted.' ); @@ -446,7 +446,7 @@ export default { test.expect(1); // tests here test.equal( - C.utf8Letter.parse(stream.ofString('-'), 0).isAccepted(), + C.utf8Letter.parse(Streams.ofString('-'), 0).isAccepted(), false, 'should be rejected.' ); @@ -456,7 +456,7 @@ export default { test.expect(1); // tests here test.equal( - C.utf8Letter.parse(stream.ofString(''), 0).isAccepted(), + C.utf8Letter.parse(Streams.ofString(''), 0).isAccepted(), false, 'should be rejected.' ); @@ -466,13 +466,13 @@ export default { 'expect emoji to be accepted': function (test) { // It's super important for emoji to test there is EOS just after, // because some emoji takes two \uWXYZ codes, where utf_8 does not - test.ok(! C.emoji.then(F.eos).parse(stream.ofString('б'), 0).isAccepted()); - test.ok(! C.emoji.then(F.eos).parse(stream.ofString('a'), 0).isAccepted()); + test.ok(! C.emoji.then(F.eos).parse(Streams.ofString('б'), 0).isAccepted()); + test.ok(! C.emoji.then(F.eos).parse(Streams.ofString('a'), 0).isAccepted()); // multiple emojis are also accepted as one - test.ok(C.emoji.then(F.eos).parse(stream.ofString('🐵🐵✈️'), 0).isAccepted()); - test.ok(C.emoji.then(F.eos).parse(stream.ofString('✈️'), 0).isAccepted()); + test.ok(C.emoji.then(F.eos).parse(Streams.ofString('🐵🐵✈️'), 0).isAccepted()); + test.ok(C.emoji.then(F.eos).parse(Streams.ofString('✈️'), 0).isAccepted()); // Emoji 5.0 released in June 2017. - test.ok(C.emoji.then(F.eos).parse(stream.ofString('🥪')).isAccepted()); + test.ok(C.emoji.then(F.eos).parse(Streams.ofString('🥪')).isAccepted()); test.done(); } diff --git a/src/test/parsec/flow-bundle-test.js b/src/test/parsec/flow-bundle-test.js index 179ed8e..3a31a5d 100644 --- a/src/test/parsec/flow-bundle-test.js +++ b/src/test/parsec/flow-bundle-test.js @@ -1,12 +1,12 @@ -import stream from '../../lib/stream/index'; +import Streams from '../../lib/stream/index'; import {F, C} from '../../lib/parsec/index'; let value = undefined; let accepted = undefined; function testParser(parser, string) { - let myStream = stream.ofString(string); - let parsing = parser.parse(myStream); + let stream = Streams.ofString(string); + let parsing = parser.parse(stream); value = parsing.value; accepted = parsing.isAccepted(); diff --git a/src/test/standard/token-test.js b/src/test/standard/token-test.js index 0f6c84a..c3be9bb 100644 --- a/src/test/standard/token-test.js +++ b/src/test/standard/token-test.js @@ -1,13 +1,13 @@ import T from '../../lib/standard/token-bundle'; -import stream from '../../lib/stream/index'; +import Streams from '../../lib/stream/index'; import {F, C} from '../../lib/parsec/index'; let value = undefined; let accepted = undefined; function testParser(parser, string) { - let myStream = stream.ofString(string); - let parsing = parser.parse(myStream); + let stream = Streams.ofString(string); + let parsing = parser.parse(stream); value = parsing.value; accepted = parsing.isAccepted();