Skip to content

Commit

Permalink
Add test for new entity parsing. Should fix isaacs#139 & Adobe Illust…
Browse files Browse the repository at this point in the history
…rator files with _ in names.
  • Loading branch information
thiakil committed Oct 10, 2015
1 parent 7ee9841 commit 0836892
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/xml_internal_entities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var i_expect = [], my_attributes = {}, ENTITIES = {};

//generates xml like test0="&control;"
var entities_to_test= {
// 'ENTITY_NAME': IS_VALID || [invalid_char_pos, invalid_char],
'control0': true,//This is a vanilla control.
//entityStart
'_uscore': true,
'#hash': true,
':colon': true,
'-bad': [0, '-'],
'.bad': [0, '.'],
//general entity
'u_score': true,
'd-ash': true,
'd.ot': true,
'all:_#-.': true,
};

var xml_start = '<a test="&amp;" ',
xml_end = '/>';

i_expect.push(['attribute', {name: 'test', value: '&'}]);
my_attributes['test'] = '&';

var ent_i=0;


for (entity in entities_to_test){
var attrib_name = "test"+ent_i, attrib_value = "Testing "+entity;
xml_start += attrib_name+'="'+'&';//add the first part to use in calculation below
if (typeof entities_to_test[entity] == "object"){
i_expect.push(['error', "Invalid character entity\nLine: 0\nColumn: "+(xml_start.length+entities_to_test[entity][0]+1)+"\nChar: "+entities_to_test[entity][1]]);
i_expect.push(['attribute', {name: attrib_name, value: '&'+entity+';'}]);
my_attributes[attrib_name] = '&'+entity+';';
} else {
ENTITIES[entity] = attrib_value;
i_expect.push(['attribute', {name: attrib_name, value: attrib_value}]);
my_attributes[attrib_name] = attrib_value;
}

xml_start += entity+';" ';
ent_i++;
}

i_expect.push(['opentag', {'name':'a', attributes:my_attributes, isSelfClosing: true}]);
i_expect.push(['closetag', 'a']);

var parser = require(__dirname).test({
strict: true,
expect: i_expect
});

for (entity in entities_to_test){
parser.ENTITIES[entity] = ENTITIES[entity];
}

parser.write(xml_start+xml_end).close();

0 comments on commit 0836892

Please sign in to comment.