Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
0d87e836
Commit
0d87e836
authored
Aug 14, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make fact into theory
parent
dfccbd4a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
21 deletions
+16
-21
Parse.cs
StackExchange.Redis.Tests/Parse.cs
+16
-21
No files found.
StackExchange.Redis.Tests/Parse.cs
View file @
0d87e836
...
...
@@ -9,10 +9,11 @@ namespace StackExchange.Redis.Tests
public
class
Parse
:
TestBase
{
public
Parse
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
]
public
void
EvilParse
()
[
Theory
]
[
InlineData
(
"$4\r\nPING\r\n$4\r\nPONG\r\n$4\r\r"
,
2
)]
public
void
ParseAsSingleChunk
(
string
ascii
,
int
expected
)
{
ReadOnlySequence
<
byte
>
buffer
=
new
ReadOnlySequence
<
byte
>(
Encoding
.
ASCII
.
GetBytes
(
$"$4\r\nPING\r\n$4\r\nPONG\r\n"
));
ReadOnlySequence
<
byte
>
buffer
=
new
ReadOnlySequence
<
byte
>(
Encoding
.
ASCII
.
GetBytes
(
ascii
));
var
reader
=
new
BufferReader
(
buffer
);
...
...
@@ -23,37 +24,31 @@ public void EvilParse()
Writer
.
WriteLine
(
$"
{
result
}
-
{
result
.
GetString
()}
"
);
found
++;
}
Assert
.
Equal
(
2
,
found
);
Assert
.
Equal
(
expected
,
found
);
}
class
FragmentedSegment
:
ReadOnlySequenceSegment
<
byte
>
{
public
FragmentedSegment
(
long
runningIndex
,
ReadOnlyMemory
<
byte
>
memory
)
{
RunningIndex
=
runningIndex
;
Memory
=
memory
;
}
public
new
FragmentedSegment
Next
{
get
=>
(
FragmentedSegment
)
base
.
Next
;
set
=>
base
.
Next
=
value
;
}
public
new
ReadOnlyMemory
<
byte
>
Memory
{
get
=>
base
.
Memory
;
set
=>
base
.
Memory
=
value
;
}
public
new
long
RunningIndex
{
get
=>
base
.
RunningIndex
;
set
=>
base
.
RunningIndex
=
value
;
}
}
[
Fact
]
public
void
EvilParse2
()
[
Theory
]
[
InlineData
(
"$4\r\nPING\r\n$4\r\nPONG\r\n$4\r\r"
,
2
)]
public
void
ParseAsLotsOfChunks
(
string
ascii
,
int
messages
)
{
var
bytes
=
Encoding
.
ASCII
.
GetBytes
(
$"$4\r\nPING\r\n$4\r\nPONG\r\n"
);
var
bytes
=
Encoding
.
ASCII
.
GetBytes
(
ascii
);
FragmentedSegment
chain
=
null
,
tail
=
null
;
for
(
int
i
=
0
;
i
<
bytes
.
Length
;
i
++)
{
var
next
=
new
FragmentedSegment
();
next
.
RunningIndex
=
i
;
next
.
Memory
=
new
ReadOnlyMemory
<
byte
>(
bytes
,
i
,
1
);
var
next
=
new
FragmentedSegment
(
i
,
new
ReadOnlyMemory
<
byte
>(
bytes
,
i
,
1
));
if
(
tail
==
null
)
{
chain
=
next
;
...
...
@@ -77,7 +72,7 @@ public void EvilParse2()
Writer
.
WriteLine
(
$"
{
result
}
-
{
result
.
GetString
()}
"
);
found
++;
}
Assert
.
Equal
(
2
,
found
);
Assert
.
Equal
(
messages
,
found
);
}
}
}
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