Added test for chaining calls to add, plus addSegment.
diff --git a/js/testing/test-name.html b/js/testing/test-name.html
index aca50d9..318511d 100644
--- a/js/testing/test-name.html
+++ b/js/testing/test-name.html
@@ -32,73 +32,81 @@
var name1 = new Name([entree, comp1, ab2]);
var name1Uri = name1.to_uri();
var name1UriExpected = "/entr%C3%A9e/..../%00%01%02%03";
- result.innerHTML += "Name from '" + entree + "', Uint8Array of '.' and ArrayBuffer of 0,1,2,3:<br>";
+ result.innerHTML += "Name from '" + entree + "', Uint8Array of '.' and ArrayBuffer of 0,1,2,3:<br/>";
if (name1Uri == name1UriExpected)
- result.innerHTML += "SUCCESS: " + name1Uri + ".<br>";
+ result.innerHTML += "SUCCESS: " + name1Uri + ".<br/>";
else
- result.innerHTML += "ERROR: got " + name1Uri + ", expected " + name1UriExpected + " .<br>";
+ result.innerHTML += "ERROR: got " + name1Uri + ", expected " + name1UriExpected + " .<br/>";
- result.innerHTML += "Compare with same Name from '" + entree + "', '.' and ArrayBuffer:<br>";
+ result.innerHTML += "Compare with same Name from '" + entree + "', '.' and ArrayBuffer:<br/>";
// Equivalent with name1
var name2 = new Name([entree, ".", comp2]);
if (name2.components.length != name1.components.length)
result.innerHTML += "ERROR: Got name with " + name2.components.length +
- " components, expected " + name1.components.length + ".<br>";
+ " components, expected " + name1.components.length + ".<br/>";
else {
var allEqual = true;
for (var i = 0; i < name1.components.length; ++i) {
if (!DataUtils.arraysEqual(name1.components[i], name2.components[i])) {
allEqual = false;
- result.innerHTML += "ERROR: Names differ at component at index " + i + ".<br>";
+ result.innerHTML += "ERROR: Names differ at component at index " + i + ".<br/>";
}
}
if (allEqual)
- result.innerHTML += "SUCCESS: Names are equal.<br>";
+ result.innerHTML += "SUCCESS: Names are equal.<br/>";
}
- result.innerHTML += "Compare with same Name from URI:<br>";
+ result.innerHTML += "Compare with same Name from URI:<br/>";
// Equivalent with name1; when Name constructor is passed a string, it is treated as a URI
var name3 = new Name("/entr%C3%A9e/..../%00%01%02%03");
if (name3.components.length != name1.components.length)
result.innerHTML += "ERROR: Got name with " + name3.components.length +
- " components, expected " + name1.components.length + ".<br>";
+ " components, expected " + name1.components.length + ".<br/>";
else {
var allEqual = true;
for (var i = 0; i < name1.components.length; ++i) {
if (!DataUtils.arraysEqual(name1.components[i], name3.components[i])) {
allEqual = false;
- result.innerHTML += "ERROR: Names differ at component at index " + i + ".<br>";
+ result.innerHTML += "ERROR: Names differ at component at index " + i + ".<br/>";
}
}
if (allEqual)
- result.innerHTML += "SUCCESS: Names are equal.<br>";
+ result.innerHTML += "SUCCESS: Names are equal.<br/>";
}
- result.innerHTML += "Compare with Name prefix of first 2 components:<br>";
+ result.innerHTML += "Compare with Name prefix of first 2 components:<br/>";
// Returns new Name([entree, "."])
var name4 = name2.getPrefix(2);
if (name4.components.length != 2)
result.innerHTML += "ERROR: Got name with " + name4.components.length +
- " components, expected 2.<br>";
+ " components, expected 2.<br/>";
else {
var allEqual = true;
for (var i = 0; i < name4.components.length; ++i) {
if (!DataUtils.arraysEqual(name1.components[i], name4.components[i])) {
allEqual = false;
- result.innerHTML += "ERROR: Names differ at component at index " + i + ".<br>";
+ result.innerHTML += "ERROR: Names differ at component at index " + i + ".<br/>";
}
}
if (allEqual)
- result.innerHTML += "SUCCESS: First 2 components are equal: " + name4.to_uri() + " .<br>";
+ result.innerHTML += "SUCCESS: First 2 components are equal: " + name4.to_uri() + " .<br/>";
}
- result.innerHTML += "Check with Name component at index 2:<br>";
+ result.innerHTML += "Check with Name component at index 2:<br/>";
// Returns ArrayBuffer of "%00%01%02%03"
var component2Out = new Uint8Array(name1.getComponent(2));
if (DataUtils.arraysEqual(component2Out, comp2))
- result.innerHTML += "SUCCESS: Components at index 2 are equal.<br>";
+ result.innerHTML += "SUCCESS: Components at index 2 are equal.<br/>";
else
- result.innerHTML += "ERROR: Components at index 2 are different.<br>";
+ result.innerHTML += "ERROR: Components at index 2 are different.<br/>";
+
+ var name5 = new Name("/localhost/user/folders/files/%00%0F");
+ result.innerHTML += "Check chaining calls to add() to create Name: " + name5.to_uri() + "<br/>";
+ if (name5.equalsName(new Name(new Name("/localhost")).add(new Name("/user/folders")).add
+ ("files").addSegment(15)))
+ result.innerHTML += "SUCCESS: Names are equal.<br/>";
+ else
+ result.innerHTML += "ERROR: Names are different.<br/>";
}
</script>