-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pretty print attributes. Closes #167
- Loading branch information
Showing
4 changed files
with
176 additions
and
12 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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
suite 'Creating XML with string writer:', -> | ||
test 'Pretty print attributes - 1', -> | ||
eq( | ||
xml('test', { headless: true }) | ||
.ele('node', {"first":"1", "second":"2"}) | ||
.end({ pretty: true, width: 20 }) | ||
""" | ||
<test> | ||
<node first="1" | ||
second="2"/> | ||
</test> | ||
""" | ||
) | ||
|
||
test 'Pretty print attributes - 2', -> | ||
eq( | ||
xml('test', { headless: true }) | ||
.ele('node', {"first":"1", "second":"2", "third":"33333333333333333333", "fourth": 4}) | ||
.end({ pretty: true, width: 10 }) | ||
""" | ||
<test> | ||
<node | ||
first="1" | ||
second="2" | ||
third="33333333333333333333" | ||
fourth="4"/> | ||
</test> | ||
""" | ||
) | ||
|
||
test 'Pretty print attributes - 3', -> | ||
eq( | ||
xml('test', { headless: true }) | ||
.ele('node', {"first":"1", "second":"2", "third":"33333333333333333333", "fourth": 4}) | ||
.end({ pretty: true, width: 1 }) | ||
""" | ||
<test> | ||
<node | ||
first="1" | ||
second="2" | ||
third="33333333333333333333" | ||
fourth="4"/> | ||
</test> | ||
""" | ||
) | ||
|
||
test 'Pretty print attributes - 4', -> | ||
eq( | ||
xml('test', { headless: true }) | ||
.ele('node', {"first":"1", "second":"2"}).ele('child') | ||
.end({ pretty: true, width: 10 }) | ||
""" | ||
<test> | ||
<node | ||
first="1" | ||
second="2"> | ||
<child/> | ||
</node> | ||
</test> | ||
""" | ||
) |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
suite 'Creating XML with stream writer:', -> | ||
hook = null | ||
setup 'hook stdout.write', -> | ||
hook = captureStream(process.stdout) | ||
return | ||
teardown 'unhook stdout.write', -> | ||
hook.unhook() | ||
return | ||
|
||
test 'Pretty print attributes - 1', -> | ||
xml('test', { headless: true }) | ||
.ele('node', {"first":"1", "second":"2"}) | ||
.end(builder.streamWriter(process.stdout, { pretty: true, width: 20 })) | ||
eq( | ||
hook.captured() | ||
""" | ||
<test> | ||
<node first="1" | ||
second="2"/> | ||
</test> | ||
""" | ||
) | ||
|
||
test 'Pretty print attributes - 2', -> | ||
xml('test', { headless: true }) | ||
.ele('node', {"first":"1", "second":"2", "third":"33333333333333333333", "fourth": 4}) | ||
.end(builder.streamWriter(process.stdout, { pretty: true, width: 10 })) | ||
eq( | ||
hook.captured() | ||
""" | ||
<test> | ||
<node | ||
first="1" | ||
second="2" | ||
third="33333333333333333333" | ||
fourth="4"/> | ||
</test> | ||
""" | ||
) | ||
|
||
test 'Pretty print attributes - 3', -> | ||
xml('test', { headless: true }) | ||
.ele('node', {"first":"1", "second":"2", "third":"33333333333333333333", "fourth": 4}) | ||
.end(builder.streamWriter(process.stdout, { pretty: true, width: 1 })) | ||
eq( | ||
hook.captured() | ||
""" | ||
<test> | ||
<node | ||
first="1" | ||
second="2" | ||
third="33333333333333333333" | ||
fourth="4"/> | ||
</test> | ||
""" | ||
) | ||
|
||
test 'Pretty print attributes - 4', -> | ||
xml('test', { headless: true }) | ||
.ele('node', {"first":"1", "second":"2"}).ele('child') | ||
.end(builder.streamWriter(process.stdout, { pretty: true, width: 10 })) | ||
eq( | ||
hook.captured() | ||
""" | ||
<test> | ||
<node | ||
first="1" | ||
second="2"> | ||
<child/> | ||
</node> | ||
</test> | ||
""" | ||
) |