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

ENH: Return null on exception in expression language #1829

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

effigies
Copy link
Collaborator

This makes Javascript happier.

@effigies effigies requested a review from rwblair October 19, 2023 19:18
@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (27141af) 85.72% compared to head (3d967f6) 83.56%.

❗ Current head 3d967f6 differs from pull request most recent head c47caa5. Consider uploading reports for the commit c47caa5 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1829      +/-   ##
==========================================
- Coverage   85.72%   83.56%   -2.16%     
==========================================
  Files         132       92      -40     
  Lines        6711     3895    -2816     
  Branches     1558     1272     -286     
==========================================
- Hits         5753     3255    -2498     
+ Misses        850      542     -308     
+ Partials      108       98      -10     

see 40 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@effigies
Copy link
Collaborator Author

Combined with bids-standard/bids-specification#1629:

❯ BIDS_SCHEMA=$HOME/Projects/bids/validator/test-schema.json deno test --allow-all src/tests/schema-expression-language.test.ts
running 1 test from ./src/tests/schema-expression-language.test.ts
validate schema expression tests ...
  sidecar.MissingValue evals to null ... ok (6ms)
  null.anything evals to null ... ok (3ms)
  (null) evals to null ... ok (4ms)
  null[0] evals to null ... ok (4ms)
  null && true evals to null ... ok (4ms)
  true && null evals to null ... ok (3ms)
  false && null evals to false ... ok (4ms)
  true || null evals to true ... ok (4ms)
  null || true evals to true ... ok (3ms)
  false || null evals to null ... ok (3ms)
  !null evals to true ... ok (2ms)
  intersects([], null) evals to false ... ok (3ms)
  intersects(null, []) evals to false ... ok (3ms)
  match(null, 'pattern') evals to null ... ok (5ms)
  match('string', null) evals to false ... ok (5ms)
  substr(null, 1, 4) evals to null ... ok (3ms)
  substr('string', null, 4) evals to null ... ok (5ms)
  substr('string', 1, null) evals to null ... ok (4ms)
  min(null) evals to null ... ok (3ms)
  max(null) evals to null ... ok (3ms)
  length(null) evals to null ... ok (5ms)
  type(null) evals to null ... ok (5ms)
  null == false evals to false ... ok (3ms)
  null == true evals to false ... ok (5ms)
  null != false evals to true ... ok (3ms)
  null != true evals to true ... ok (3ms)
  null != 1.5 evals to true ... ok (4ms)
  null == null evals to true ... ok (4ms)
  null == 1 evals to false ... ok (3ms)
  "VolumeTiming" in null evals to null ... ok (4ms)
  exists(null, "bids-uri") evals to 0 ... ok (4ms)
  exists([], null) evals to 0 ... ok (3ms)
  true || sidecar.MissingValue evals to true ... ok (4ms)
  1 + 2 evals to 3 ... ok (4ms)
  "cat" + "dog" evals to catdog ... ok (3ms)
  match('string', '.*') evals to true ... ok (3ms)
  match('', '.') evals to false ... ok (4ms)
  substr('string', 1, 4) evals to tri ... ok (4ms)
  substr('string', 0, 20) evals to string ... ok (4ms)
  type(1) evals to number ... ok (4ms)
  type([]) evals to array ... ok (4ms)
  type({}) evals to object ... ok (4ms)
  type(true) evals to boolean ... ok (4ms)
  intersects([1], [1, 2]) evals to true ... ok (4ms)
  intersects([1], []) evals to false ... ok (4ms)
  length([1, 2, 3]) evals to 3 ... ok (3ms)
  length([]) evals to 0 ... ok (3ms)
  count([1, 2, 3], 1) evals to 1 ... ok (4ms)
  index(["i", "j", "k"], "i") evals to 0 ... ok (4ms)
  index(["i", "j", "k"], "j") evals to 1 ... ok (5ms)
  index(["i", "j", "k"], "x") evals to null ... ok (4ms)
  sorted([3, 2, 1]) evals to 1,2,3 ... ok (4ms)
  min([-1, "n/a", 1]) evals to -1 ... ok (4ms)
  max([-1, "n/a", 1]) evals to 1 ... ok (5ms)
  [3, 2, 1][0] evals to 3 ... ok (4ms)
  "string"[0] evals to s ... ok (3ms)
------- output -------
  expression                   desired actual  result
  sidecar.MissingValue         null    null    pass  
  null.anything                null    null    pass  
  (null)                       null    null    pass  
  null[0]                      null    null    pass  
  null && true                 null    null    pass  
  true && null                 null    null    pass  
  false && null                false   false   pass  
  true || null                 true    true    pass  
  null || true                 true    true    pass  
  false || null                null    null    pass  
  !null                        true    true    pass  
  intersects([], null)         false   false   pass  
  intersects(null, [])         false   false   pass  
  match(null, 'pattern')       null    null    pass  
  match('string', null)        false   false   pass  
  substr(null, 1, 4)           null    null    pass  
  substr('string', null, 4)    null    null    pass  
  substr('string', 1, null)    null    null    pass  
  min(null)                    null    null    pass  
  max(null)                    null    null    pass  
  length(null)                 null    null    pass  
  type(null)                   null    null    pass  
  null == false                false   false   pass  
  null == true                 false   false   pass  
  null != false                true    true    pass  
  null != true                 true    true    pass  
  null != 1.5                  true    true    pass  
  null == null                 true    true    pass  
  null == 1                    false   false   pass  
  "VolumeTiming" in null       null    null    pass  
  exists(null, "bids-uri")     0       0       pass  
  exists([], null)             0       0       pass  
  true || sidecar.MissingValue true    true    pass  
  1 + 2                        3       3       pass  
  "cat" + "dog"                catdog  catdog  pass  
  match('string', '.*')        true    true    pass  
  match('', '.')               false   false   pass  
  substr('string', 1, 4)       tri     tri     pass  
  substr('string', 0, 20)      string  string  pass  
  type(1)                      number  number  pass  
  type([])                     array   array   pass  
  type({})                     object  object  pass  
  type(true)                   boolean boolean pass  
  intersects([1], [1, 2])      true    true    pass  
  intersects([1], [])          false   false   pass  
  length([1, 2, 3])            3       3       pass  
  length([])                   0       0       pass  
  count([1, 2, 3], 1)          1       1       pass  
  index(["i", "j", "k"], "i")  0       0       pass  
  index(["i", "j", "k"], "j")  1       1       pass  
  index(["i", "j", "k"], "x")  null    null    pass  
  sorted([3, 2, 1])            1,2,3   1,2,3   pass  
  min([-1, "n/a", 1])          -1      -1      pass  
  max([-1, "n/a", 1])          1       1       pass  
  [3, 2, 1][0]                 3       3       pass  
  "string"[0]                  s       s       pass  
----- output end -----
validate schema expression tests ... ok (247ms)

ok | 1 passed (56 steps) | 0 failed (278ms)

@rwblair rwblair merged commit 78fbf69 into bids-standard:master Oct 19, 2023
20 of 24 checks passed
@effigies effigies deleted the fix/expressions branch October 23, 2023 13: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

Successfully merging this pull request may close these issues.

2 participants