Skip to content

Commit 7d4a2f3

Browse files
author
Eduardo V. Bruno
authored
Merge pull request #120 from fauna/revert-to-string
Revert ToString
2 parents b1710ea + e886127 commit 7d4a2f3

File tree

11 files changed

+15
-105
lines changed

11 files changed

+15
-105
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
- Add `Reverse` function
44
- Add new Fauna attributes annotations:`FaunaString`, `FaunaTime`, and `FaunaDate`
55
- implicit `BytesV` conversion from `bytes[]`
6-
- Improve `ToString` for Fauna types
76
- Support versioned lambdas
87

98
## 2.12.0

FaunaDB.Client.Test/EncoderTest.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using FaunaDB.Query;
43
using FaunaDB.Types;
54
using NUnit.Framework;
65

@@ -398,49 +397,5 @@ public void TestStringOverride()
398397
Encode(new StringOverride(testUri, testGuid))
399398
);
400399
}
401-
402-
[Test]
403-
public void TestToStringTypes()
404-
{
405-
Assert.AreEqual(
406-
"SetRef({\"match\": Ref(id=\"spells_by_element\", collection=Ref(id=\"indexes\")), \"terms\": \"water\"})",
407-
new SetRefV(new Dictionary<string, Value>() {
408-
{ "terms", StringV.Of("water") },
409-
{ "match", new RefV("spells_by_element", new RefV("indexes")) }
410-
}).ToString()
411-
);
412-
413-
Assert.AreEqual("true", BooleanV.Of(true).ToString());
414-
Assert.AreEqual("3.14", DoubleV.Of(3.14).ToString());
415-
Assert.AreEqual("42", LongV.Of(42).ToString());
416-
Assert.AreEqual("null", NullV.Instance.ToString());
417-
Assert.AreEqual("Date(\"2001-01-01\")", new DateV("2001-01-01").ToString());
418-
Assert.AreEqual("Time(\"2000-01-01T01:10:30.123Z\")", new TimeV("2000-01-01T01:10:30.123Z").ToString());
419-
Assert.AreEqual(@"[1, 3.14, true, ""foo bar"", ""my \""quote""]", ArrayV.Of(1, 3.14, true, "foo bar", "my \"quote").ToString());
420-
Assert.AreEqual("Bytes(0x01, 0x02, 0x03)", BytesV.Of(0x1, 0x2, 0x3).ToString());
421-
422-
Assert.AreEqual("{\"answer\": 42, \"question\": \"meaning\"}",
423-
ObjectV.With("answer", 42, "question", "meaning").ToString());
424-
Assert.AreEqual("{\"answer\": 42, \"question\": \"meaning\"}",
425-
ObjectV.With("question", "meaning", "answer", 42).ToString());
426-
427-
Assert.AreEqual(
428-
"Query({\"api_version\": \"3\", \"expr\": {\"add\": [{\"var\": \"x\"}, 1]}, \"lambda\": \"x\"})",
429-
new QueryV(new Dictionary<string, Expr>() {
430-
{"lambda", StringV.Of("x")},
431-
{"expr", ObjectV.With("add", ArrayV.Of(ObjectV.With("var", "x"), 1))},
432-
{ "api_version", StringV.Of("3") }
433-
}).ToString()
434-
);
435-
436-
Assert.AreEqual(
437-
"Query({\"api_version\": \"3\", \"expr\": {\"add\": [{\"var\": \"x\"}, 1, 3.14]}, \"lambda\": \"x\"})",
438-
new QueryV(new Dictionary<string, Expr>() {
439-
{"lambda", "x"},
440-
{"expr", Add(Var("x"), 1, 3.14)},
441-
{ "api_version", "3" }
442-
}).ToString()
443-
);
444-
}
445400
}
446401
}
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Linq;
1+
using System.Linq;
32
using System.Collections.Generic;
43

54
namespace FaunaDB.Collections
@@ -26,24 +25,6 @@ public static bool DictEquals<TKey, TValue>(this IReadOnlyDictionary<TKey, TValu
2625

2726
public static Dictionary<TKey, TValue> FilterNulls<TKey, TValue>(this Dictionary<TKey, TValue> dict) =>
2827
dict.Where(kv => kv.Value != null).ToDictionary(kv => kv.Key, kv => kv.Value);
29-
30-
public static string Debug<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> source)
31-
where TKey: IComparable
32-
{
33-
List<TKey> elements = source.Keys.ToList();
34-
elements.Sort();
35-
36-
string[] result = new string[elements.Count];
37-
38-
for (int i = 0; i < result.Length; i++)
39-
{
40-
var key = elements[i];
41-
var value = source[key].ToString();
42-
result[i] = $"\"{key}\": {value}";
43-
}
44-
45-
return string.Join(", ", result);
46-
}
4728
}
4829
}
4930

FaunaDB.Client/Query/Unescaped.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ protected internal override void WriteJson(JsonWriter writer) =>
3636

3737
public override string ToString()
3838
{
39-
var props = Values.Debug();
40-
return $"{{{props}}}";
39+
var props = string.Join(",", from kv in Values select $"{kv.Key}: {kv.Value}");
40+
return $"UObject({props})";
4141
}
4242

4343
public static UnescapedObject With(Dictionary<string, Expr> exprs) =>
@@ -101,6 +101,6 @@ protected internal override void WriteJson(JsonWriter writer) =>
101101
writer.WriteArray(Value);
102102

103103
public override string ToString() =>
104-
$"[{string.Join(", ", Value)}]";
104+
$"UArr({string.Join(", ", Value)})";
105105
}
106106
}

FaunaDB.Client/Types/ArrayV.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected override int HashCode() =>
8181
HashUtil.Hash(Value);
8282

8383
public override string ToString() =>
84-
$"[{string.Join(", ", Value)}]";
84+
$"Arr({string.Join(", ", Value)})";
8585
#endregion
8686
}
8787
}

FaunaDB.Client/Types/BytesV.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected internal override void WriteJson(JsonWriter writer)
4848
public override string ToString()
4949
{
5050
var str = Value.Select(b => string.Format("0x{0:x2}", b));
51-
return "Bytes(" + string.Join(", ", str) + ")";
51+
return "BytesV(" + string.Join(", ", str) + ")";
5252
}
5353

5454
/// <summary>

FaunaDB.Client/Types/NullV.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override bool Equals(Expr v) =>
2222
object.ReferenceEquals(this, v);
2323

2424
public override string ToString() =>
25-
"null";
25+
"NullV";
2626

2727
protected override int HashCode() =>
2828
0;

FaunaDB.Client/Types/ObjectV.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ protected override int HashCode() =>
7878

7979
public override string ToString()
8080
{
81-
var props = Value.Debug();
82-
return $"{{{props}}}";
81+
var props = string.Join(",", from kv in Value select $"{kv.Key}: {kv.Value}");
82+
return $"ObjectV({props})";
8383
}
8484
#endregion
8585

FaunaDB.Client/Types/QueryV.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,5 @@ public override bool Equals(Expr v)
3030
var w = v as QueryV;
3131
return w != null && Value.DictEquals(w.Value);
3232
}
33-
34-
public override string ToString()
35-
{
36-
var content = Value.Debug();
37-
return $"Query({{{content}}})";
38-
}
3933
}
4034
}

FaunaDB.Client/Types/RefV.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ protected override int HashCode() =>
6262

6363
public override string ToString()
6464
{
65-
var cls = Collection != null ? $", collection={Collection}" : string.Empty;
66-
var db = Database != null ? $", database={Database}" : string.Empty;
65+
var cls = Collection != null ? $", collection = {Collection}" : string.Empty;
66+
var db = Database != null ? $", database = {Database}" : string.Empty;
6767

68-
return $"Ref(id=\"{Id}\"{cls}{db})";
68+
return $"RefV(id = \"{Id}\"{cls}{db})";
6969
}
7070
}
7171

0 commit comments

Comments
 (0)