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
f923aead
Commit
f923aead
authored
Jun 28, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add redisvalue equivalency tests ... and fix the gaps :)
parent
a8cbbf69
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
221 additions
and
155 deletions
+221
-155
KeysAndValues.cs
StackExchange.Redis.Tests/KeysAndValues.cs
+13
-50
RedisValueEquivalency.cs
StackExchange.Redis.Tests/RedisValueEquivalency.cs
+154
-0
Format.cs
StackExchange.Redis/StackExchange/Redis/Format.cs
+10
-1
RedisValue.cs
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
+44
-104
No files found.
StackExchange.Redis.Tests/KeysAndValues.cs
View file @
f923aead
...
...
@@ -62,19 +62,19 @@ public void TestValues()
CheckNotSame
(
bool1
,
bool2
);
}
private
void
CheckSame
(
RedisValue
x
,
RedisValue
y
)
internal
static
void
CheckSame
(
RedisValue
x
,
RedisValue
y
)
{
Assert
.
True
(
Equals
(
x
,
y
));
Assert
.
True
(
Equals
(
y
,
x
));
Assert
.
True
(
EqualityComparer
<
RedisValue
>.
Default
.
Equals
(
x
,
y
));
Assert
.
True
(
EqualityComparer
<
RedisValue
>.
Default
.
Equals
(
y
,
x
));
Assert
.
True
(
x
==
y
);
Assert
.
True
(
y
==
x
);
Assert
.
False
(
x
!=
y
);
Assert
.
False
(
y
!=
x
);
Assert
.
True
(
x
.
Equals
(
y
));
Assert
.
True
(
y
.
Equals
(
x
));
Assert
.
True
(
x
.
GetHashCode
()
==
y
.
GetHashCode
());
Assert
.
True
(
Equals
(
x
,
y
)
,
"Equals(x, y)"
);
Assert
.
True
(
Equals
(
y
,
x
)
,
"Equals(y, x)"
);
Assert
.
True
(
EqualityComparer
<
RedisValue
>.
Default
.
Equals
(
x
,
y
)
,
"EQ(x,y)"
);
Assert
.
True
(
EqualityComparer
<
RedisValue
>.
Default
.
Equals
(
y
,
x
)
,
"EQ(y,x)"
);
Assert
.
True
(
x
==
y
,
"x==y"
);
Assert
.
True
(
y
==
x
,
"y==x"
);
Assert
.
False
(
x
!=
y
,
"x!=y"
);
Assert
.
False
(
y
!=
x
,
"y!=x"
);
Assert
.
True
(
x
.
Equals
(
y
)
,
"x.EQ(y)"
);
Assert
.
True
(
y
.
Equals
(
x
)
,
"y.EQ(x)"
);
Assert
.
True
(
x
.
GetHashCode
()
==
y
.
GetHashCode
()
,
"GetHashCode"
);
}
private
void
CheckNotSame
(
RedisValue
x
,
RedisValue
y
)
...
...
@@ -108,7 +108,7 @@ private void CheckNotNull(RedisValue value)
CheckNotSame
(
value
,
(
byte
[])
null
);
}
private
void
CheckNull
(
RedisValue
value
)
internal
static
void
CheckNull
(
RedisValue
value
)
{
Assert
.
True
(
value
.
IsNull
);
Assert
.
True
(
value
.
IsNullOrEmpty
);
...
...
@@ -172,42 +172,5 @@ public void CanBeDynamic()
Assert
.
Equal
((
byte
)
'b'
,
blob
[
1
]);
Assert
.
Equal
((
byte
)
'c'
,
blob
[
2
]);
}
[
Fact
]
public
void
TryParse
()
{
{
RedisValue
val
=
"1"
;
Assert
.
True
(
val
.
TryParse
(
out
int
i
));
Assert
.
Equal
(
1
,
i
);
Assert
.
True
(
val
.
TryParse
(
out
long
l
));
Assert
.
Equal
(
1L
,
l
);
Assert
.
True
(
val
.
TryParse
(
out
double
d
));
Assert
.
Equal
(
1.0
,
l
);
}
{
RedisValue
val
=
"8675309"
;
Assert
.
True
(
val
.
TryParse
(
out
int
i
));
Assert
.
Equal
(
8675309
,
i
);
Assert
.
True
(
val
.
TryParse
(
out
long
l
));
Assert
.
Equal
(
8675309L
,
l
);
Assert
.
True
(
val
.
TryParse
(
out
double
d
));
Assert
.
Equal
(
8675309.0
,
l
);
}
{
RedisValue
val
=
"3.14159"
;
Assert
.
True
(
val
.
TryParse
(
out
double
d
));
Assert
.
Equal
(
3.14159
,
d
);
}
{
RedisValue
val
=
"not a real number"
;
Assert
.
False
(
val
.
TryParse
(
out
int
i
));
Assert
.
False
(
val
.
TryParse
(
out
long
l
));
Assert
.
False
(
val
.
TryParse
(
out
double
d
));
}
}
}
}
StackExchange.Redis.Tests/RedisValueEquivalency.cs
0 → 100644
View file @
f923aead
using
System.Text
;
using
Xunit
;
namespace
StackExchange.Redis.Tests
{
public
class
RedisValueEquivalency
{
// internal storage types: null, integer, double, string, raw
// public perceived types: int, long, double, bool, memory / byte[]
[
Fact
]
public
void
Int32_Matrix
()
{
void
Check
(
RedisValue
known
,
RedisValue
test
)
{
KeysAndValues
.
CheckSame
(
known
,
test
);
if
(
known
.
IsNull
)
{
Assert
.
True
(
test
.
IsNull
);
Assert
.
False
(((
int
?)
test
).
HasValue
);
}
else
{
Assert
.
False
(
test
.
IsNull
);
Assert
.
Equal
((
int
)
known
,
((
int
?)
test
).
Value
);
Assert
.
Equal
((
int
)
known
,
(
int
)
test
);
}
Assert
.
Equal
((
int
)
known
,
(
int
)
test
);
}
Check
(
42
,
42
);
Check
(
42
,
42.0
);
Check
(
42
,
"42"
);
Check
(
42
,
"42.0"
);
Check
(
42
,
Bytes
(
"42"
));
Check
(
42
,
Bytes
(
"42.0"
));
CheckString
(
42
,
"42"
);
Check
(-
42
,
-
42
);
Check
(-
42
,
-
42.0
);
Check
(-
42
,
"-42"
);
Check
(-
42
,
"-42.0"
);
Check
(-
42
,
Bytes
(
"-42"
));
Check
(-
42
,
Bytes
(
"-42.0"
));
CheckString
(-
42
,
"-42"
);
Check
(
1
,
true
);
Check
(
0
,
false
);
}
[
Fact
]
public
void
Int64_Matrix
()
{
void
Check
(
RedisValue
known
,
RedisValue
test
)
{
KeysAndValues
.
CheckSame
(
known
,
test
);
if
(
known
.
IsNull
)
{
Assert
.
True
(
test
.
IsNull
);
Assert
.
False
(((
long
?)
test
).
HasValue
);
}
else
{
Assert
.
False
(
test
.
IsNull
);
Assert
.
Equal
((
long
)
known
,
((
long
?)
test
).
Value
);
Assert
.
Equal
((
long
)
known
,
(
long
)
test
);
}
Assert
.
Equal
((
long
)
known
,
(
long
)
test
);
}
Check
(
1099511627848
,
1099511627848
);
Check
(
1099511627848
,
1099511627848.0
);
Check
(
1099511627848
,
"1099511627848"
);
Check
(
1099511627848
,
"1099511627848.0"
);
Check
(
1099511627848
,
Bytes
(
"1099511627848"
));
Check
(
1099511627848
,
Bytes
(
"1099511627848.0"
));
CheckString
(
1099511627848
,
"1099511627848"
);
Check
(-
1099511627848
,
-
1099511627848
);
Check
(-
1099511627848
,
-
1099511627848
);
Check
(-
1099511627848
,
"-1099511627848"
);
Check
(-
1099511627848
,
"-1099511627848.0"
);
Check
(-
1099511627848
,
Bytes
(
"-1099511627848"
));
Check
(-
1099511627848
,
Bytes
(
"-1099511627848.0"
));
CheckString
(-
1099511627848
,
"-1099511627848"
);
Check
(
1L
,
true
);
Check
(
0L
,
false
);
}
[
Fact
]
public
void
Double_Matrix
()
{
void
Check
(
RedisValue
known
,
RedisValue
test
)
{
KeysAndValues
.
CheckSame
(
known
,
test
);
if
(
known
.
IsNull
)
{
Assert
.
True
(
test
.
IsNull
);
Assert
.
False
(((
double
?)
test
).
HasValue
);
}
else
{
Assert
.
False
(
test
.
IsNull
);
Assert
.
Equal
((
double
)
known
,
((
double
?)
test
).
Value
);
Assert
.
Equal
((
double
)
known
,
(
double
)
test
);
}
Assert
.
Equal
((
double
)
known
,
(
double
)
test
);
}
Check
(
1099511627848.0
,
1099511627848
);
Check
(
1099511627848.0
,
1099511627848.0
);
Check
(
1099511627848.0
,
"1099511627848"
);
Check
(
1099511627848.0
,
"1099511627848.0"
);
Check
(
1099511627848.0
,
Bytes
(
"1099511627848"
));
Check
(
1099511627848.0
,
Bytes
(
"1099511627848.0"
));
CheckString
(
1099511627848.0
,
"1099511627848"
);
Check
(-
1099511627848.0
,
-
1099511627848
);
Check
(-
1099511627848.0
,
-
1099511627848
);
Check
(-
1099511627848.0
,
"-1099511627848"
);
Check
(-
1099511627848.0
,
"-1099511627848.0"
);
Check
(-
1099511627848.0
,
Bytes
(
"-1099511627848"
));
Check
(-
1099511627848.0
,
Bytes
(
"-1099511627848.0"
));
CheckString
(-
1099511627848.0
,
"-1099511627848"
);
Check
(
1.0
,
true
);
Check
(
0.0
,
false
);
Check
(
1099511627848.6001
,
1099511627848.6001
);
Check
(
1099511627848.6001
,
"1099511627848.6001"
);
Check
(
1099511627848.6001
,
Bytes
(
"1099511627848.6001"
));
CheckString
(
1099511627848.6001
,
"1099511627848.6001"
);
Check
(-
1099511627848.6001
,
-
1099511627848.6001
);
Check
(-
1099511627848.6001
,
"-1099511627848.6001"
);
Check
(-
1099511627848.6001
,
Bytes
(
"-1099511627848.6001"
));
CheckString
(-
1099511627848.6001
,
"-1099511627848.6001"
);
Check
(
double
.
NegativeInfinity
,
double
.
NegativeInfinity
);
Check
(
double
.
NegativeInfinity
,
"-inf"
);
CheckString
(
double
.
NegativeInfinity
,
"-inf"
);
Check
(
double
.
PositiveInfinity
,
double
.
PositiveInfinity
);
Check
(
double
.
PositiveInfinity
,
"+inf"
);
CheckString
(
double
.
PositiveInfinity
,
"+inf"
);
}
static
void
CheckString
(
RedisValue
value
,
string
expected
)
{
var
s
=
value
.
ToString
();
Assert
.
True
(
s
==
expected
,
$"'
{
s
}
' vs '
{
expected
}
'"
);
}
static
byte
[]
Bytes
(
string
s
)
=>
s
==
null
?
null
:
Encoding
.
UTF8
.
GetBytes
(
s
);
}
}
StackExchange.Redis/StackExchange/Redis/Format.cs
View file @
f923aead
...
...
@@ -62,7 +62,16 @@ internal static string ToString(double value)
return
value
.
ToString
(
"G17"
,
NumberFormatInfo
.
InvariantInfo
);
}
internal
static
string
ToString
(
object
value
)
=>
Convert
.
ToString
(
value
,
CultureInfo
.
InvariantCulture
);
internal
static
string
ToString
(
object
value
)
{
if
(
value
==
null
)
return
""
;
if
(
value
is
long
l
)
return
ToString
(
l
);
if
(
value
is
int
i
)
return
ToString
(
i
);
if
(
value
is
float
f
)
return
ToString
(
f
);
if
(
value
is
double
d
)
return
ToString
(
d
);
if
(
value
is
EndPoint
e
)
return
ToString
(
e
);
return
Convert
.
ToString
(
value
,
CultureInfo
.
InvariantCulture
);
}
internal
static
string
ToString
(
EndPoint
endpoint
)
{
...
...
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
View file @
f923aead
This diff is collapsed.
Click to expand it.
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