-Refactor ExceptionAssert

This commit is contained in:
James Newton-King
2014-09-12 21:33:53 +12:00
parent 4b9ce67ab7
commit dfb2ac17a5
43 changed files with 979 additions and 1482 deletions
@@ -104,25 +104,19 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void RootWithBadWhitespace()
{
ExceptionAssert.Throws<JsonException>(
@"Unexpected character while parsing path: ",
() => { new JPath("$ .Blah"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("$ .Blah"); }, @"Unexpected character while parsing path: ");
}
[Test]
public void NoFieldNameAfterDot()
{
ExceptionAssert.Throws<JsonException>(
@"Unexpected end while parsing path.",
() => { new JPath("$.Blah."); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("$.Blah."); }, @"Unexpected end while parsing path.");
}
[Test]
public void RootWithBadWhitespace2()
{
ExceptionAssert.Throws<JsonException>(
@"Unexpected character while parsing path: ",
() => { new JPath("$. Blah"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("$. Blah"); }, @"Unexpected character while parsing path: ");
}
[Test]
@@ -273,9 +267,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void SinglePropertyAndFilterWithUnknownEscape()
{
ExceptionAssert.Throws<JsonException>(
@"Unknown escape chracter: \i",
() => { new JPath(@"Blah[ ?( @.name=='h\i' ) ]"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath(@"Blah[ ?( @.name=='h\i' ) ]"); }, @"Unknown escape chracter: \i");
}
[Test]
@@ -425,57 +417,49 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void BadOr1()
{
ExceptionAssert.Throws<JsonException>("Unexpected character while parsing path query: )",
() => new JPath("[?(@.name||)]"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||)]"), "Unexpected character while parsing path query: )");
}
[Test]
public void BaddOr2()
{
ExceptionAssert.Throws<JsonException>("Unexpected character while parsing path query: |",
() => new JPath("[?(@.name|)]"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name|)]"), "Unexpected character while parsing path query: |");
}
[Test]
public void BaddOr3()
{
ExceptionAssert.Throws<JsonException>("Unexpected character while parsing path query: |",
() => new JPath("[?(@.name|"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name|"), "Unexpected character while parsing path query: |");
}
[Test]
public void BaddOr4()
{
ExceptionAssert.Throws<JsonException>("Path ended with open query.",
() => new JPath("[?(@.name||"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||"), "Path ended with open query.");
}
[Test]
public void NoAtAfterOr()
{
ExceptionAssert.Throws<JsonException>("Unexpected character while parsing path query: s",
() => new JPath("[?(@.name||s"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||s"), "Unexpected character while parsing path query: s");
}
[Test]
public void NoPathAfterAt()
{
ExceptionAssert.Throws<JsonException>(@"Path ended with open query.",
() => new JPath("[?(@.name||@"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||@"), @"Path ended with open query.");
}
[Test]
public void NoPathAfterDot()
{
ExceptionAssert.Throws<JsonException>(@"Unexpected end while parsing path.",
() => new JPath("[?(@.name||@."));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||@."), @"Unexpected end while parsing path.");
}
[Test]
public void NoPathAfterDot2()
{
ExceptionAssert.Throws<JsonException>(@"Unexpected end while parsing path.",
() => new JPath("[?(@.name||@.)]"));
ExceptionAssert.Throws<JsonException>(() => new JPath("[?(@.name||@.)]"), @"Unexpected end while parsing path.");
}
[Test]
@@ -502,17 +486,13 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void BadCharactersInIndexer()
{
ExceptionAssert.Throws<JsonException>(
@"Unexpected character while parsing path indexer: [",
() => { new JPath("Blah[[0]].Two.Three[1].Four"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("Blah[[0]].Two.Three[1].Four"); }, @"Unexpected character while parsing path indexer: [");
}
[Test]
public void UnclosedIndexer()
{
ExceptionAssert.Throws<JsonException>(
@"Path ended with open indexer.",
() => { new JPath("Blah[0"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("Blah[0"); }, @"Path ended with open indexer.");
}
[Test]
@@ -634,17 +614,13 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void EmptyIndexer()
{
ExceptionAssert.Throws<JsonException>(
"Array index expected.",
() => { new JPath("[]"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("[]"); }, "Array index expected.");
}
[Test]
public void IndexerCloseInProperty()
{
ExceptionAssert.Throws<JsonException>(
"Unexpected character while parsing path: ]",
() => { new JPath("]"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("]"); }, "Unexpected character while parsing path: ]");
}
[Test]
@@ -661,9 +637,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
[Test]
public void MissingDotAfterIndexer()
{
ExceptionAssert.Throws<JsonException>(
"Unexpected character following indexer: B",
() => { new JPath("[1]Blah"); });
ExceptionAssert.Throws<JsonException>(() => { new JPath("[1]Blah"); }, "Unexpected character following indexer: B");
}
}
}