| 1 |
dojo.provide("dojox.html.tests.entities"); |
| 2 |
dojo.require("dojox.html.entities"); |
| 3 |
|
| 4 |
doh.register("dojox.html.tests.entities", |
| 5 |
[ |
| 6 |
{ |
| 7 |
name: "Encode: Basic HTML Entities", |
| 8 |
runTest: function(t) { |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
var txt = "This is some \" text \" with & entities inside it that <need to be escaped>"; |
| 14 |
var expected = "This is some " text " with & entities inside it that <need to be escaped>"; |
| 15 |
var encodedTxt = dojox.html.entities.encode(txt); |
| 16 |
doh.assertEqual(expected, encodedTxt); |
| 17 |
} |
| 18 |
}, |
| 19 |
{ |
| 20 |
name: "Decode: Basic HTML Entities", |
| 21 |
runTest: function(t) { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
var txt = "This is some " text " with & entities inside it that <need to be escaped>"; |
| 27 |
var expected = "This is some \" text \" with & entities inside it that <need to be escaped>"; |
| 28 |
var decodedTxt = dojox.html.entities.decode(txt); |
| 29 |
doh.assertEqual(expected, decodedTxt); |
| 30 |
} |
| 31 |
}, |
| 32 |
{ |
| 33 |
name: "Encode: Basic Latin Entities", |
| 34 |
runTest: function(t) { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
var txt = ""; |
| 40 |
var expected = ""; |
| 41 |
var map = dojox.html.entities.latin; |
| 42 |
var i; |
| 43 |
for(i = 0; i < map.length; i++){ |
| 44 |
txt += map[i][0]; |
| 45 |
expected += "&" + map[i][1] + ";"; |
| 46 |
} |
| 47 |
var encodedTxt = dojox.html.entities.encode(txt); |
| 48 |
doh.assertEqual(expected, encodedTxt); |
| 49 |
} |
| 50 |
}, |
| 51 |
{ |
| 52 |
name: "Decode: Basic Latin Entities", |
| 53 |
runTest: function(t) { |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
var txt = ""; |
| 59 |
var expected = ""; |
| 60 |
var map = dojox.html.entities.latin; |
| 61 |
var i; |
| 62 |
for(i = 0; i < map.length; i++){ |
| 63 |
txt += "&" + map[i][1] + ";"; |
| 64 |
expected += map[i][0]; |
| 65 |
} |
| 66 |
var decodedTxt = dojox.html.entities.decode(txt); |
| 67 |
doh.assertEqual(expected, decodedTxt); |
| 68 |
} |
| 69 |
}, |
| 70 |
{ |
| 71 |
name: "Encode: Custom entity map", |
| 72 |
runTest: function(t) { |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
var txt = "This is some \" text with & entities inside it that <need to be escaped>"; |
| 78 |
var expected = "This is some " text with & entities inside it that <need to be escaped>"; |
| 79 |
var encodedTxt = dojox.html.entities.encode(txt, [["\"", "quot"]]); |
| 80 |
doh.assertEqual(expected, encodedTxt); |
| 81 |
} |
| 82 |
}, |
| 83 |
{ |
| 84 |
name: "Decode: Custom entity map", |
| 85 |
runTest: function(t) { |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
var txt = "This is some " text with & entities inside it that <need to be escaped>"; |
| 91 |
var expected = "This is some \" text with & entities inside it that <need to be escaped>"; |
| 92 |
var decodedTxt = dojox.html.entities.decode(txt, [["\"", "quot"]]); |
| 93 |
doh.assertEqual(expected, decodedTxt); |
| 94 |
} |
| 95 |
} |
| 96 |
] |
| 97 |
); |