From 82ca4f40f771223a3ebe04d29df7af2f3bf66794 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sat, 20 Dec 2014 13:03:57 -0500 Subject: [PATCH] Adding initial tests for Repeat nodes --- spec/parser/javascript/repeat_spec.js | 167 ++++++++++++++++++++++++++ src/js/parser/javascript/repeat.js | 6 +- 2 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 spec/parser/javascript/repeat_spec.js diff --git a/spec/parser/javascript/repeat_spec.js b/spec/parser/javascript/repeat_spec.js new file mode 100644 index 0000000..20926b8 --- /dev/null +++ b/spec/parser/javascript/repeat_spec.js @@ -0,0 +1,167 @@ +import javascript from 'src/js/parser/javascript/parser.js'; +import _ from 'lodash'; +import Snap from 'snapsvg'; + +describe('parser/javascript/any_character.js', function() { + + _.forIn({ + '*': { + minimum: 0, + maximum: -1, + greedy: true, + hasSkip: true, + hasLoop: true + }, + '*?': { + minimum: 0, + maximum: -1, + greedy: false, + hasSkip: true, + hasLoop: true + }, + '+': { + minimum: 1, + maximum: -1, + greedy: true, + hasSkip: false, + hasLoop: true + }, + '+?': { + minimum: 1, + maximum: -1, + greedy: false, + hasSkip: false, + hasLoop: true + }, + '?': { + minimum: 0, + maximum: 1, + greedy: true, + hasSkip: true, + hasLoop: false + }, + '??': { + minimum: 0, + maximum: 1, + greedy: false, + hasSkip: true, + hasLoop: false + }, + '{1}': { + minimum: 1, + maximum: 1, + greedy: true, + hasSkip: false, + hasLoop: false + }, + '{1}?': { + minimum: 1, + maximum: 1, + greedy: false, + hasSkip: false, + hasLoop: false + }, + '{2}': { + minimum: 2, + maximum: 2, + greedy: true, + hasSkip: false, + hasLoop: true + }, + '{2}?': { + minimum: 2, + maximum: 2, + greedy: false, + hasSkip: false, + hasLoop: true + }, + '{0,}': { + minimum: 0, + maximum: -1, + greedy: true, + hasSkip: true, + hasLoop: true + }, + '{0,}?': { + minimum: 0, + maximum: -1, + greedy: false, + hasSkip: true, + hasLoop: true + }, + '{1,}': { + minimum: 1, + maximum: -1, + greedy: true, + hasSkip: false, + hasLoop: true + }, + '{1,}?': { + minimum: 1, + maximum: -1, + greedy: false, + hasSkip: false, + hasLoop: true + }, + '{0,1}': { + minimum: 0, + maximum: 1, + greedy: true, + hasSkip: true, + hasLoop: false + }, + '{0,1}?': { + minimum: 0, + maximum: 1, + greedy: false, + hasSkip: true, + hasLoop: false + }, + '{0,2}': { + minimum: 0, + maximum: 2, + greedy: true, + hasSkip: true, + hasLoop: true + }, + '{0,2}?': { + minimum: 0, + maximum: 2, + greedy: false, + hasSkip: true, + hasLoop: true + }, + '{1,2}': { + minimum: 1, + maximum: 2, + greedy: true, + hasSkip: false, + hasLoop: true + }, + '{1,2}?': { + minimum: 1, + maximum: 2, + greedy: false, + hasSkip: false, + hasLoop: true + } + }, (content, str) => { + it(`parses "${str}" as a Repeat`, function() { + var parser = new javascript.Parser(str); + expect(parser.__consume__repeat()).toEqual(jasmine.objectContaining(content)); + }); + }); + + describe('contentPosition property', function() { + + pending(); + + }); + + describe('label property', function() { + + pending(); + + }); + +}); diff --git a/src/js/parser/javascript/repeat.js b/src/js/parser/javascript/repeat.js index 73c420f..0ba0af4 100644 --- a/src/js/parser/javascript/repeat.js +++ b/src/js/parser/javascript/repeat.js @@ -35,7 +35,7 @@ export default { if (this.minimum === this.maximum) { return formatTimes(this.minimum - 1); } else { - return `${this.minimum - 1}...${formatTimes(this.maximum - 1)}`; + return `${this.minimum - 1}\u2026${formatTimes(this.maximum - 1)}`; } } } @@ -46,7 +46,7 @@ export default { this.minimum = this.properties.spec.minimum; this.maximum = this.properties.spec.maximum; this.greedy = (this.properties.greedy.textValue === ''); - this.hasSkip = this.minimum === 0; - this.hasLoop = this.maximum === -1 || this.maximum > 1; + this.hasSkip = (this.minimum === 0); + this.hasLoop = (this.maximum === -1 || this.maximum > 1); } }