@@ -391,15 +391,27 @@ class QueryTests: XCTestCase {
391391 let value = TestCodable ( int: 1 , string: " 2 " , bool: true , float: 3 , double: 4 ,
392392 date: Date ( timeIntervalSince1970: 0 ) , optional: nil , sub: value1)
393393 let update = try emails. update ( value)
394- let encodedJSON = try JSONEncoder ( ) . encode ( value1)
395- let encodedJSONString = String ( data: encodedJSON, encoding: . utf8) !
396- assertSQL (
394+
395+ // NOTE: As Linux JSON decoding doesn't order keys the same way, we need to check prefix, suffix,
396+ // and extract JSON to decode it and check the decoded object.
397+
398+ let expectedPrefix =
397399 """
398400 UPDATE \" emails \" SET \" int \" = 1, \" string \" = '2', \" bool \" = 1, \" float \" = 3.0, \" double \" = 4.0,
399- \" date \" = '1970-01-01T00:00:00.000', \" sub \" = ' \( encodedJSONString) '
400- """ . replacingOccurrences ( of: " \n " , with: " " ) ,
401- update
402- )
401+ \" date \" = '1970-01-01T00:00:00.000', \" sub \" = '
402+ """ . replacingOccurrences ( of: " \n " , with: " " )
403+ let expectedSuffix = " ' "
404+
405+ let sql = update. asSQL ( )
406+ XCTAssert ( sql. hasPrefix ( expectedPrefix) )
407+ XCTAssert ( sql. hasSuffix ( expectedSuffix) )
408+
409+ let extractedJSON = String ( sql [
410+ sql. index ( sql. startIndex, offsetBy: expectedPrefix. count) ..<
411+ sql. index ( sql. endIndex, offsetBy: - expectedSuffix. count)
412+ ] )
413+ let decodedJSON = try JSONDecoder ( ) . decode ( TestCodable . self, from: extractedJSON. data ( using: . utf8) !)
414+ XCTAssertEqual ( decodedJSON, value1)
403415 }
404416
405417 func test_delete_compilesDeleteExpression( ) {
0 commit comments