Skip to content

Commit

Permalink
test: verify custom (duplicate) namespace confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Apr 11, 2024
1 parent 7076834 commit 327a512
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/spec/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,70 @@ describe('Reader', function() {
});
});


it.only('duplicate custom ns declaration', async function() {

Check failure on line 560 in test/spec/reader.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

Unexpected exclusive mocha test

var extensionModel = createModel([ 'extension/base' ]);

// given
var reader = new Reader(extensionModel);
var rootHandler = reader.handler('b:Root');

var xml =
'<b:Root xmlns="http://foo" xmlns:foo="http://foo" xmlns:b="http://base" foo:bar="1" />';

// when
var {
rootElement
} = await reader.fromXML(xml, rootHandler);

expect(rootElement).to.jsonEqual({
$type: 'b:Root'
});

expect(rootElement.$attrs).to.jsonEqual({
'xmlns:b': 'http://base',
'xmlns:foo': 'http://foo',
'xmlns': 'http://foo',
'foo:bar': '1'
});
});


it.only('duplicate custom ns declaration, generic element attribute', async function() {

Check failure on line 589 in test/spec/reader.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

Unexpected exclusive mocha test

var extensionModel = createModel([ 'extension/base' ]);

// given
var reader = new Reader(extensionModel);
var rootHandler = reader.handler('b:Root');

var xml =
'<b:Root xmlns="http://foo" xmlns:foo="http://foo" xmlns:b="http://base">' +
'<generic foo:bar="1" />' +
'</b:Root>';

// when
var {
rootElement
} = await reader.fromXML(xml, rootHandler);

expect(rootElement).to.jsonEqual({
$type: 'b:Root',
generic: {
$type: 'ns0:generic',
bar: '1'
}
});

expect(rootElement.$attrs).to.jsonEqual({
'xmlns:b': 'http://base',
'xmlns:foo': 'http://foo',
'xmlns': 'http://foo',
'foo:bar': '1'
});
});

});


Expand Down Expand Up @@ -1767,6 +1831,7 @@ describe('Reader', function() {
'xmlns': 'http://extensions'
});
});

});


Expand Down
29 changes: 29 additions & 0 deletions test/spec/rountrip.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,35 @@ describe('Roundtrip', function() {
expect(output).to.eql(input);
});


it.only('should keep custom namespace', async function() {

Check failure on line 377 in test/spec/rountrip.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

Unexpected exclusive mocha test

// given
var extendedModel = createModel([ 'extension/base' ]);

var reader = new Reader(extendedModel);
var writer = createWriter(extendedModel);

var rootHandler = reader.handler('b:Root');

var input =
'<b:Root xmlns="http://foo" xmlns:foo="http://foo" xmlns:b="http://base" foo:bar="1">' +
'<generic foo:bar="1" />' +
'<b:own foo:bar="1" />' +
'</b:Root>';

// when
var {
rootElement
} = await reader.fromXML(input, rootHandler);

var output = writer.toXML(rootElement);

// then
expect(output).to.eql(input);
});


});


Expand Down

0 comments on commit 327a512

Please sign in to comment.