usethesource / rascal

The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
http://www.rascal-mpl.org
Other
408 stars 77 forks source link

toJSON and fromJSON were deprecated and replaced by asJSON and parseJSON but the new functions do not pass the tests. #2086

Open jurgenvinju opened 4 days ago

jurgenvinju commented 4 days ago

Describe the bug

If we replace:

bool writeRead(type[&T] returnType, &T dt) {
    if (!jsonFeaturesSupported(dt)) {
        return true;
    }
    json = toJSON(dt);
    return fromJSON(returnType, json) == dt;
}

by the newer:

bool writeRead(type[&T] returnType, &T dt) {
    if (!jsonFeaturesSupported(dt)) {
        return true;
    }
    json = asJSON(dt);
    return parseJSON(returnType, json) == dt;
}

We get this:

rascal>:test
Running tests for lang::rascal::tests::library::lang::json::JSONIOTests
Warning: selecting arbitrary constructor for Enum                                           
- testing 6/22 failure: jsonWithNode1 @ |file:///Users/jurgenv/git/rascal/src/org/rascalmpl/library/lang/rascal/tests/library/lang/json/JSONIOTests.rsc|(1516,57,<47,0>,<47,57>)
Test lang::rascal::tests::library::lang::json::JSONIOTests::jsonWithNode1 failed due to
        test returned false

Actual parameters:
        node =>"4"("uO","UeJG")

- testing 11/22 failure: jsonRandom1 @ |file:///Users/jurgenv/git/rascal/src/org/rascalmpl/library/lang/rascal/tests/library/lang/json/JSONIOTests.rsc|(1696,56,<52,0>,<52,56>)
Test lang::rascal::tests::library::lang::json::JSONIOTests::jsonRandom1 failed due to
        test returned false

Actual parameters:
        value =><"">

- testing 15/22 error: jsonWithDatetime1 @ |file:///Users/jurgenv/git/rascal/src/org/rascalmpl/library/lang/rascal/tests/library/lang/json/JSONIOTests.rsc|(1243,68,<43,0>,<43,68>)
        /Users/jurgenv/git/rascal/src/org/rascalmpl/library/lang/json/IO.rsc:73,0: IO("Dates as strings not yet implemented: yyyy-MM-dd\'T\'HH:mm:ssZZZZZ")
        at *** somewhere ***(|file:///Users/jurgenv/git/rascal/src/org/rascalmpl/library/lang/json/IO.rsc|(4673,442,<73,0>,<78,240>))
        at asJSON(|file:///Users/jurgenv/git/rascal/src/org/rascalmpl/library/lang/json/IO.rsc|(5108,5,<78,233>,<78,238>))
        at jsonWithDatetime1(|file:///Users/jurgenv/git/rascal/src/org/rascalmpl/library/lang/rascal/tests/library/lang/json/JSONIOTests.rsc|(1243,68,<43,0>,<43,68>))
        at $shell$(|main://$shell$|)
\ testing 21/22 failure: jsonWithNum1 @ |file:///Users/jurgenv/git/rascal/src/org/rascalmpl/library/lang/rascal/tests/library/lang/json/JSONIOTests.rsc|(1080,53,<39,0>,<39,53>)
Test lang::rascal::tests::library::lang::json::JSONIOTests::jsonWithNum1 failed due to
        test returned false

Actual parameters:
        num =>0.0

Test report for lang::rascal::tests::library::lang::json::JSONIOTests
        18/22 tests succeeded
        3/22 tests failed
        1/22 tests threw exceptions
bool: false