Adding initial tests for Repeat nodes

This commit is contained in:
Jeff Avallone 2014-12-20 13:03:57 -05:00
parent 79cda13dc5
commit 82ca4f40f7
2 changed files with 170 additions and 3 deletions

View File

@ -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();
});
});

View File

@ -35,7 +35,7 @@ export default {
if (this.minimum === this.maximum) { if (this.minimum === this.maximum) {
return formatTimes(this.minimum - 1); return formatTimes(this.minimum - 1);
} else { } 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.minimum = this.properties.spec.minimum;
this.maximum = this.properties.spec.maximum; this.maximum = this.properties.spec.maximum;
this.greedy = (this.properties.greedy.textValue === ''); this.greedy = (this.properties.greedy.textValue === '');
this.hasSkip = this.minimum === 0; this.hasSkip = (this.minimum === 0);
this.hasLoop = this.maximum === -1 || this.maximum > 1; this.hasLoop = (this.maximum === -1 || this.maximum > 1);
} }
} }