Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
zilf
zilf
Commits
e75185f66895
Commit
3343baaf
authored
Oct 23, 2020
by
Jesse McGrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transform non-XML-safe characters in test console output.
parent
6b0c3831295c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
test/Zilf.Tests.Integration/ZlrHelper.cs
test/Zilf.Tests.Integration/ZlrHelper.cs
+16
-2
No files found.
test/Zilf.Tests.Integration/ZlrHelper.cs
View file @
e75185f6
...
...
@@ -30,6 +30,7 @@ using Zilf.Diagnostics;
using
Zilf.Interpreter.Values
;
using
ZLR.VM
;
using
Zilf.Language
;
using
System.Text.RegularExpressions
;
namespace
Zilf.Tests.Integration
{
...
...
@@ -153,10 +154,23 @@ namespace Zilf.Tests.Integration
this
.
input
=
input
;
}
private
static
readonly
Regex
_invalidXMLChars
=
new
Regex
(
@"(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFEFF\uFFFE\uFFFF]"
,
RegexOptions
.
Compiled
);
/// <summary>
/// https://stackoverflow.com/questions/397250/unicode-regex-invalid-xml-characters/961504#961504
/// </summary>
static
string
TransformInvalidXMLChars
(
string
text
)
{
if
(
string
.
IsNullOrEmpty
(
text
))
return
""
;
return
_invalidXMLChars
.
Replace
(
text
,
m
=>
$"\uFFFD\\u
{(
int
)
m
.
Value
[
0
]:
X4
}
"
);
}
void
PrintZilCode
()
{
Console
.
Error
.
WriteLine
(
"=== {0} ==="
,
SZilFileName
);
Console
.
Error
.
WriteLine
(
code
);
Console
.
Error
.
WriteLine
(
TransformInvalidXMLChars
(
code
)
)
;
Console
.
Error
.
WriteLine
();
}
...
...
@@ -171,7 +185,7 @@ namespace Zilf.Tests.Integration
var
zapStream
=
zilfOutputFiles
[
filename
];
var
zapCode
=
Encoding
.
UTF8
.
GetString
(
zapStream
.
ToArray
());
Console
.
Error
.
WriteLine
(
"=== {0} ==="
,
filename
);
Console
.
Error
.
WriteLine
(
zapCode
);
Console
.
Error
.
WriteLine
(
TransformInvalidXMLChars
(
zapCode
)
)
;
Console
.
Error
.
WriteLine
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment