Skip to content
This repository has been archived by the owner on Feb 15, 2021. It is now read-only.

Commit

Permalink
Cleaned up tests.
Browse files Browse the repository at this point in the history
Fixed errors caused by previous changes.
  • Loading branch information
Greg Dennis committed Sep 23, 2016
1 parent a5827f7 commit ac3725b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 135 deletions.
4 changes: 2 additions & 2 deletions Manatee.Json.Tests/Path/FilterExpressionTest.cs
Expand Up @@ -6,13 +6,13 @@ namespace Manatee.Json.Tests.Path
[TestClass]
public class FilterExpressionParseTest
{
private void Run(JsonPath expected, string text)
private static void Run(JsonPath expected, string text)
{
var actual = JsonPath.Parse(text);
Assert.AreEqual(expected, actual);
}

private void CompareEval(JsonPath expected, string text)
private static void CompareEval(JsonPath expected, string text)
{
var data = new JsonArray
{
Expand Down
80 changes: 13 additions & 67 deletions Manatee.Json.Tests/Path/IndexExpressionParseTest.cs
Expand Up @@ -6,7 +6,7 @@ namespace Manatee.Json.Tests.Path
[TestClass]
public class IndexExpressionParseTest
{
private void Run(JsonPath expected, string text)
private static void Run(JsonPath expected, string text)
{
var actual = JsonPath.Parse(text);
Assert.AreEqual(expected, actual);
Expand All @@ -15,82 +15,42 @@ private void Run(JsonPath expected, string text)
[TestMethod]
public void Length()
{
var text = "$[(@.length)]";
var expected = JsonPathWith.Array(jv => jv.Length());

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => jv.Length()), "$[(@.length)]");
}
[TestMethod]
public void Length_Root()
{
var text = "$[($.length)]";
var expected = JsonPathWith.Array(jv => JsonPathRoot.Length());

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => JsonPathRoot.Length()), "$[($.length)]");
}
[TestMethod]
public void ExtendedLength()
{
var text = "$[(@.name.length)]";
var expected = JsonPathWith.Array(jv => jv.Name("name").Length());

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => jv.Name("name").Length()), "$[(@.name.length)]");
}
[TestMethod]
public void Addition()
{
var text = "$[(@.length+1)]";
var expected = JsonPathWith.Array(jv => jv.Length() + 1);

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => jv.Length() + 1), "$[(@.length+1)]");
}
[TestMethod]
public void Subtraction()
{
var text = "$[(@.length-1)]";
var expected = JsonPathWith.Array(jv => jv.Length() - 1);

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => jv.Length() - 1), "$[(@.length-1)]");
}
[TestMethod]
public void Multiplication()
{
var text = "$[(@.length*1)]";
var expected = JsonPathWith.Array(jv => jv.Length()*1);

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => jv.Length() * 1), "$[(@.length*1)]");
}
[TestMethod]
public void Division()
{
var text = "$[(@.length/1)]";
var expected = JsonPathWith.Array(jv => jv.Length()/1);

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => jv.Length() / 1), "$[(@.length/1)]");
}
[TestMethod]
public void Modulus()
{
var text = "$[(@.length%1)]";
var expected = JsonPathWith.Array(jv => jv.Length()%1);

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => jv.Length() % 1), "$[(@.length%1)]");
}
[TestMethod]
[Ignore]
Expand All @@ -99,32 +59,18 @@ public void Modulus()
// Also not really sure JS supports it as an exponentiation operator, either.
public void Exponent()
{
var text = "$[(@.length^1)]";
var expected = JsonPathWith.Array(jv => jv.Length() ^ 1);

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => jv.Length() ^ 1), "$[(@.length^1)]");
}
[TestMethod]
public void Add3()
{
var text = "$[(3+@.length+3)]";
var expected = JsonPathWith.Array(jv => 3 + jv.Length() + 3);

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => 3 + jv.Length() + 3), "$[(3+@.length+3)]");
}
[TestMethod]
public void WhyOnGodsGreenEarthWouldAnyoneDoThis()
{
var text = "$[(4+@.length*($.name.length-2)+5)]";
var expected = JsonPathWith.Array(jv => 4 + jv.Length()*(JsonPathRoot.Name("name").Length() - 2) + 5);

var actual = JsonPath.Parse(text);

Assert.AreEqual(expected, actual);
Run(JsonPathWith.Array(jv => 4 + jv.Length()*(JsonPathRoot.Name("name").Length() - 2) + 5),
"$[(4+@.length*($.name.length-2)+5)]");
}
[TestMethod]
public void JustAnInteger()
Expand Down
17 changes: 1 addition & 16 deletions Manatee.Json.Tests/Path/ParsingFails.cs
Expand Up @@ -7,7 +7,7 @@ namespace Manatee.Json.Tests.Path
[TestClass]
public class ParsingFails
{
private void Run(string text)
private static void Run(string text)
{
try
{
Expand Down Expand Up @@ -38,106 +38,91 @@ public void EmptyFilterExpressionArray()
{
Run("$[?()]");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void EmptyObject()
{
Run("$.");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void InvalidPropertyName()
{
Run("$.tes*t");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void StringIndex()
{
// TODO: This may actually be the key to parsing bracket notation
Run("$[\"test\"]");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void BoolIndex()
{
Run("$[false]");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void MissingCloseBracket()
{
Run("$[1.test");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void BadSliceFormat()
{
Run("$[1-5]");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void MissingCloseParenthesisOnIndexExpression()
{
Run("$[(1]");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void MissingCloseBracketOnIndexExpression()
{
Run("$[(1)");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void MissingCloseBracketOnIndexExpression2()
{
Run("$[(1).test");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void MissingCloseParenthesisOnFilterExpression()
{
Run("$[?(@.name == 4].test");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void MissingCloseBracketOnFilterExpression()
{
Run("$[?(@.name == 4)");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void MissingCloseBracketOnFilterExpression2()
{
Run("$[?(@.name == 4).test");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void MissingDot()
{
Run("$name");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void DotBeforeArray()
{
Run("$.[0]");
}

[TestMethod]
[ExpectedException(typeof(JsonPathSyntaxException))]
public void TooManyDots()
Expand Down

0 comments on commit ac3725b

Please sign in to comment.