FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/src/test/java/com/jsoniter/TestString.java at master · rubythonode/java · GitHub
rubythonode
/
java
Public
forked from
json-iterator/java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
java
/
src
/
test
/
java
/
com
/
jsoniter
/
TestString.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
96 lines (80 loc) · 3.81 KB
Breadcrumbs
java
/
src
/
test
/
java
/
com
/
jsoniter
/
TestString.java
Copy path
File metadata and controls
96 lines (80 loc) · 3.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package
com
.
jsoniter
;
import
com
.
jsoniter
.
spi
.
JsonException
;
import
junit
.
framework
.
TestCase
;
import
java
.
io
.
ByteArrayInputStream
;
import
java
.
io
.
IOException
;
public
class
TestString
extends
TestCase
{
static
{
// JsonIterator.enableStreamingSupport();
}
public
void
test_ascii_string
()
throws
IOException
{
JsonIterator
iter
=
JsonIterator
.
parse
(
"'hello''world'"
.
replace
(
'\''
,
'"'
));
assertEquals
(
"hello"
,
iter
.
readString
());
assertEquals
(
"world"
,
iter
.
readString
());
iter
=
JsonIterator
.
parse
(
"'hello''world'"
.
replace
(
'\''
,
'"'
));
assertEquals
(
"hello"
,
iter
.
readStringAsSlice
().
toString
());
assertEquals
(
"world"
,
iter
.
readStringAsSlice
().
toString
());
}
public
void
test_ascii_string_with_escape
()
throws
IOException
{
JsonIterator
iter
=
JsonIterator
.
parse
(
"'he
\\
tllo'"
.
replace
(
'\''
,
'"'
));
assertEquals
(
"he
\t
llo"
,
iter
.
readString
());
}
public
void
test_utf8_string
()
throws
IOException
{
JsonIterator
iter
=
JsonIterator
.
parse
(
"'中文'"
.
replace
(
'\''
,
'"'
));
assertEquals
(
"中文"
,
iter
.
readString
());
}
public
void
test_incomplete_escape
()
throws
IOException
{
JsonIterator
iter
=
JsonIterator
.
parse
(
"
\"
\\
"
);
try
{
iter
.
readString
();
fail
();
}
catch
(
JsonException
e
) {
}
}
public
void
test_surrogate
()
throws
IOException
{
JsonIterator
iter
=
JsonIterator
.
parse
(
"
\"
\ud83d
\udc4a
\"
"
);
assertEquals
(
"
\ud83d
\udc4a
"
,
iter
.
readString
());
}
public
void
test_larger_than_buffer
()
throws
IOException
{
JsonIterator
iter
=
JsonIterator
.
parse
(
"'0123456789012345678901234567890123'"
.
replace
(
'\''
,
'"'
));
assertEquals
(
"0123456789012345678901234567890123"
,
iter
.
readString
());
}
@
org
.
junit
.
experimental
.
categories
.
Category
(
StreamingCategory
.
class
)
public
void
test_string_across_buffer
()
throws
IOException
{
JsonIterator
iter
=
JsonIterator
.
parse
(
new
ByteArrayInputStream
(
"'hello''world'"
.
replace
(
'\''
,
'"'
).
getBytes
()),
2
);
assertEquals
(
"hello"
,
iter
.
readString
());
assertEquals
(
"world"
,
iter
.
readString
());
iter
=
JsonIterator
.
parse
(
new
ByteArrayInputStream
(
"'hello''world'"
.
replace
(
'\''
,
'"'
).
getBytes
()),
2
);
assertEquals
(
"hello"
,
iter
.
readStringAsSlice
().
toString
());
assertEquals
(
"world"
,
iter
.
readStringAsSlice
().
toString
());
}
@
org
.
junit
.
experimental
.
categories
.
Category
(
StreamingCategory
.
class
)
public
void
test_utf8
()
throws
IOException
{
byte
[]
bytes
= {
'"'
, (
byte
)
0xe4
, (
byte
)
0xb8
, (
byte
)
0xad
, (
byte
)
0xe6
, (
byte
)
0x96
, (
byte
)
0x87
,
'"'
};
JsonIterator
iter
=
JsonIterator
.
parse
(
new
ByteArrayInputStream
(
bytes
),
2
);
assertEquals
(
"中文"
,
iter
.
readString
());
}
@
org
.
junit
.
experimental
.
categories
.
Category
(
StreamingCategory
.
class
)
public
void
test_normal_escape
()
throws
IOException
{
byte
[]
bytes
= {
'"'
, (
byte
)
'\\'
, (
byte
)
't'
,
'"'
};
JsonIterator
iter
=
JsonIterator
.
parse
(
new
ByteArrayInputStream
(
bytes
),
2
);
assertEquals
(
"
\t
"
,
iter
.
readString
());
}
@
org
.
junit
.
experimental
.
categories
.
Category
(
StreamingCategory
.
class
)
public
void
test_unicode_escape
()
throws
IOException
{
byte
[]
bytes
= {
'"'
, (
byte
)
'\\'
, (
byte
)
'u'
, (
byte
)
'4'
, (
byte
)
'e'
, (
byte
)
'2'
, (
byte
)
'd'
,
'"'
};
JsonIterator
iter
=
JsonIterator
.
parse
(
new
ByteArrayInputStream
(
bytes
),
2
);
assertEquals
(
"中"
,
iter
.
readString
());
}
public
void
test_null_string
()
throws
IOException
{
JsonIterator
iter
=
JsonIterator
.
parse
(
"null"
.
replace
(
'\''
,
'"'
));
assertEquals
(
null
,
iter
.
readString
());
}
public
void
test_incomplete_string
()
throws
IOException
{
try
{
JsonIterator
.
parse
(
"
\"
abc"
).
read
();
fail
();
}
catch
(
JsonException
e
) {
}
}
}
Back
|
FazBrowse Home
|
New Git URL