/*______________
| ______ | U I Z E J A V A S C R I P T F R A M E W O R K
| / / | ---------------------------------------------------
| / O / | MODULE : Uize.Test.Uize.Parse.Xml.Tag Class
| / / / |
| / / / /| | ONLINE : http://uize.com
| /____/ /__/_| | COPYRIGHT : (c)2014-2016 UIZE
| /___ | LICENSE : Available under MIT License or GNU General Public License
|_______________| http://uize.com/license.html
*/
/* Module Meta Data
type: Test
importance: 3
codeCompleteness: 100
docCompleteness: 100
*/
/*?
Introduction
The =Uize.Test.Uize.Parse.Xml.Tag= module defines a suite of unit tests for the =Uize.Parse.Xml.Tag= module.
*DEVELOPERS:* `Chris van Rensburg`
*/
Uize.module ({
name:'Uize.Test.Uize.Parse.Xml.Tag',
superclass:'Uize.Test.ParserTest',
builder:function (_superclass) {
'use strict';
return _superclass.subclass ({
staticProperties:{parserClass:'Uize.Parse.Xml.Tag'},
set:{
title:'Test for Uize.Parse.Xml.Tag Module',
test:[
Uize.Test.requiredModulesTest ([
'Uize.Parse.Xml.NodeList',
'Uize.Parse.Xml.Tag'
]),
{
title:'A tag can be parsed',
test:[
Uize.Test.ParserTest.parserTest (
'A tag may be self-closing',
[''],
{
isValid:true,
tagName:{
isValid:true,
name:'foo'
},
length:6,
childNodes:undefined
}
),
Uize.Test.ParserTest.parserTest (
'A tag may consist of a pair of opening and closing tags',
[''],
{
isValid:true,
tagName:{
isValid:true,
name:'foo'
},
childNodes:{
isValid:true,
nodes:{
length:0
}
}
}
),
Uize.Test.ParserTest.parserTest (
'A self-closing tag may contain whitespace padding around its name',
['< \n\r \t foo \r \n \t / >'],
{
isValid:true,
tagName:{
isValid:true,
name:'foo'
},
childNodes:undefined
}
),
Uize.Test.ParserTest.parserTest (
'A tag that is not self-closing may contain whitespace padding around its name in both the opening and closing tags',
['< \n\r \t foo \r \n \t >< \t\t \r / \n\n foo \r\t \n >'],
{
isValid:true,
tagName:{
isValid:true,
name:'foo'
},
childNodes:{
isValid:true,
nodes:{
length:0
}
}
}
),
Uize.Test.ParserTest.parserTest (
'Text after the terminator for a tag is extraneous and is not parsed as part of the tag',
[''],
{
isValid:true,
tagName:{
isValid:true,
name:'foo'
},
childNodes:undefined
}
),
Uize.Test.ParserTest.parserTest (
'A tag may contain a mixture of multiple different types of child nodes',
['text node 1text node 2text node 3text node 4'],
{
isValid:true,
tagName:{
isValid:true,
name:'foo'
},
childNodes:{
isValid:true,
nodes:{
0:{
isValid:true,
text:'text node 1'
},
1:{
isValid:true,
comment:'this is a comment'
},
2:{
isValid:true,
text:'text node 2'
},
3:{
isValid:true,
cdata:'this is a CDATA section'
},
4:{
isValid:true,
text:'text node 3'
},
5:{
isValid:true,
tagName:{
isValid:true,
name:'foo'
},
tagAttributes:{
isValid:true,
attributes:{
0:{
isValid:true,
name:{
isValid:true,
name:'bar'
},
value:{
isValid:true,
value:'baz'
}
},
length:1
}
}
},
6:{
isValid:true,
text:'text node 4'
},
length:7
}
}
}
),
Uize.Test.ParserTest.parserTest (
'A self-closing tag may contain attributes',
[''],
{
isValid:true,
tagName:{
isValid:true,
name:'foo'
},
tagAttributes:{
isValid:true,
attributes:{
0:{
isValid:true,
name:{
isValid:true,
name:'bar'
},
value:{
isValid:true,
value:'baz'
}
},
1:{
isValid:true,
name:{
isValid:true,
name:'qux'
},
value:{
isValid:true,
value:'nux'
}
},
2:{
isValid:true,
name:{
isValid:true,
name:'hello'
},
value:{
isValid:true,
value:'world'
}
},
length:3
}
},
childNodes:undefined
}
),
Uize.Test.ParserTest.parserTest (
'A paired tag may contain attributes',
[''],
{
isValid:true,
tagName:{
isValid:true,
name:'foo'
},
tagAttributes:{
isValid:true,
attributes:{
0:{
isValid:true,
name:{
isValid:true,
name:'bar'
},
value:{
isValid:true,
value:'baz'
}
},
1:{
isValid:true,
name:{
isValid:true,
name:'qux'
},
value:{
isValid:true,
value:'nux'
}
},
2:{
isValid:true,
name:{
isValid:true,
name:'hello'
},
value:{
isValid:true,
value:'world'
}
},
length:3
}
},
childNodes:{
isValid:true,
nodes:{
length:0
}
}
}
),
/*** tests for invalid tags ***/
Uize.Test.ParserTest.parserTest (
'An empty string is not a valid tag',
[''],
{
isValid:false,
length:0
}
),
Uize.Test.ParserTest.parserTest (
'A closing tag is not a valid tag',
[''],
{
isValid:false,
length:0
}
),
Uize.Test.ParserTest.parserTest (
'A tag may not start with whitespace',
[' '],
{
isValid:false,
length:0
}
),
Uize.Test.ParserTest.parserTest (
'A tag is not valid unless it starts with a "<" character',
['foo'],
{
isValid:false,
length:0
}
),
Uize.Test.ParserTest.parserTest (
'A closing tag without a preceding opening tag of the same name is not a valid tag',
[''],
{
isValid:false,
length:0
}
),
Uize.Test.ParserTest.parserTest (
'A tag is not valid if it is missing its tag name',
[''],
{
isValid:false,
length:0
}
),
Uize.Test.ParserTest.parserTest (
'A tag that is not self-closing is not valid if it is not paired with a closing tag',
[''],
{
isValid:false,
length:0
}
),
Uize.Test.ParserTest.parserTest (
'A tag that is not self-closing is not valid if it is not paired with a closing tag of the same name',
[''],
{
isValid:false,
length:0
}
),
Uize.Test.ParserTest.parserTest (
'A tag is not valid if it is overlapped with another tag',
[''],
{
isValid:false,
length:0
}
)
]
},
{
title:'A tag can be serialized',
test:[
Uize.Test.ParserTest.serializerTest (
'A tag with undefined child nodes is serialized as a self-closing tag',
'',
''
),
Uize.Test.ParserTest.serializerTest (
'A tag with zero child nodes is serialized as an empty paired tag',
'',
''
),
Uize.Test.ParserTest.serializerTest (
'A tag with a single text child node is serialized correctly',
'bar baz',
'bar baz'
),
Uize.Test.ParserTest.serializerTest (
'A tag with a single comment child node is serialized correctly',
'',
''
),
Uize.Test.ParserTest.serializerTest (
'A tag with a single CDATA child node is serialized correctly',
'',
''
),
Uize.Test.ParserTest.serializerTest (
'A tag with a mixture of multiple different types of child nodes is serialized correctly',
'text node 1text node 2text node 3text node 4',
'text node 1text node 2text node 3text node 4'
),
Uize.Test.ParserTest.serializerTest (
'A self-closing tag with attributes is serialized correctly',
'',
''
),
Uize.Test.ParserTest.serializerTest (
'A paired tag with attributes is serialized correctly',
'',
''
)
]
}
]
}
});
}
});