Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BS v7] Record keys "method" or "match" not encoded or decoded properly #43

Open
ryb73 opened this issue Dec 17, 2019 · 0 comments
Open

Comments

@ryb73
Copy link
Member

ryb73 commented Dec 17, 2019

In BuckleScript >= 7, records that contain fields named "match" or "method" will not be properly encoded or decoded by decco. This is not a problem in BuckleScript < 7.

open TestUtils;

[@decco]
type t = {
    method: int,
    match: int,
};

testEncode(
    "encode",
    { method: 1, match: 1 },
    t_encode, {|{"method":1,"match":1}|}
);

Js.Json.parseExn({|{"method":1,"match":1}|})
|> testGoodDecode("decode", t_decode, _, { method: 1, match: 1 });
 FAIL  lib/js/test/__tests__/ReasonNonKeywords.js
  ● encode

    expect(received).toBe(expected) // Object.is equality

    Expected: "{\"method\":1,\"match\":1}"
    Received: "{\"method_\":1,\"match_\":1}"

      at affirm (node_modules/@glennsl/bs-jest/lib/js/src/jest.js:72:40)
      at Object.<anonymous> (node_modules/@glennsl/bs-jest/lib/js/src/jest.js:249:11)

  ● decode

    thrown: Array [
      Array [
        "Failure",
        -2,
      ],
      "Decode error: Not a number (.method_)",
    ]

      18 | 
      19 | function testGoodDecode(name, decode, json, expected) {
    > 20 |   return Jest.test(name, (function (param) {
         |               ^
      21 |                 var match = Curry._1(decode, json);
      22 |                 if (match.tag) {
      23 |                   var match$1 = match[0];

      at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Object.test (node_modules/@glennsl/bs-jest/lib/js/src/jest.js:248:3)
      at Object.testGoodDecode (lib/js/test/TestUtils.js:20:15)
      at Object.<anonymous> (lib/js/test/__tests__/ReasonNonKeywords.js:64:11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant