-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(xml parser): Handle whitespace around attribute =
- Loading branch information
Showing
2 changed files
with
32 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
import {assert} from "chai"; | ||
import {XmlParser, ParserEvent, ParserEventType} from 'xml'; | ||
//import xml = require('xml'); | ||
import xml = require('xml'); | ||
|
||
describe("xml parser", () => { | ||
it("parses simple element", () => { | ||
let attributes = null; | ||
let element = null; | ||
let last_element = null; | ||
let last_attrs = null; | ||
let parser = null; | ||
|
||
var parser = new XmlParser(function (event: ParserEvent) { | ||
beforeEach(() => { | ||
parser = new xml.XmlParser(function (event: xml.ParserEvent) { | ||
switch (event.eventType) { | ||
case ParserEventType.StartElement: | ||
element = event.elementName; | ||
attributes = event.attributes; | ||
case xml.ParserEventType.StartElement: | ||
last_element = event.elementName; | ||
last_attrs = event.attributes; | ||
break; | ||
} | ||
}); | ||
}); | ||
|
||
|
||
parser.parse("<TextField text='hello' />"); | ||
it("handles whitespace around attribute =", () => { | ||
let attributes = null; | ||
let element = null; | ||
|
||
assert.equal('TextField', element); | ||
assert.equal('hello', attributes['text']); | ||
parser.parse("<TextField text = \n 'hello' />"); | ||
|
||
assert.equal('TextField', last_element); | ||
assert.equal('hello', last_attrs['text']); | ||
}); | ||
|
||
}); |