Skip to content

Commit

Permalink
Added tests that prove that 193 in Accurest works
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed Apr 9, 2016
1 parent c1b7bad commit 15c7ac1
Showing 1 changed file with 34 additions and 5 deletions.
Expand Up @@ -2,6 +2,7 @@ package com.toomuchcoding.jsonassert

import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import spock.lang.Issue
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
Expand Down Expand Up @@ -356,15 +357,43 @@ public class JsonAssertionSpec extends Specification {
def "should escape regular expression properly"() {
given:
String json = """
{
"path" : "/api/12",
"correlationId" : 123456
}
"""
{
"path" : "/api/12",
"correlationId" : 123456
}
"""
expect:
DocumentContext parsedJson = JsonPath.parse(json)
def verifiable = assertThatJson(parsedJson).field("path").matches("^/api/[0-9]{2}\$")
verifiable.jsonPath() == '''$[?(@.path =~ /^\\/api\\/[0-9]{2}$/)]'''
}

@Issue("Accurest#193")
def "should escape single quotes in a quoted string"() {
given:
String json = """
{
"text" : "text with 'quotes' inside"
}
"""
expect:
DocumentContext parsedJson = JsonPath.parse(json)
def verifiable = assertThatJson(parsedJson).field("text").isEqualTo("text with 'quotes' inside")
verifiable.jsonPath() == '''$[?(@.text == 'text with \\'quotes\\' inside')]'''
}

@Issue("Accurest#193")
def "should escape double quotes in a quoted string"() {
given:
String json = """
{
"text" : "text with \\"quotes\\" inside"
}
"""
expect:
DocumentContext parsedJson = JsonPath.parse(json)
def verifiable = assertThatJson(parsedJson).field("text").isEqualTo('''text with "quotes" inside''')
verifiable.jsonPath() == '''$[?(@.text == 'text with "quotes" inside')]'''
}

}

0 comments on commit 15c7ac1

Please sign in to comment.