libcyaml icon indicating copy to clipboard operation
libcyaml copied to clipboard

Add test for optional boolean

Open FortStatement opened this issue 2 years ago • 3 comments

I couldn't trivially tell if the default for boolean should be true or false, figured there should be a test for it. (Especially since it seems inverted looking at cyaml__read_bool)

FortStatement avatar Apr 19 '22 12:04 FortStatement

Codecov Report

Merging #184 (cf5495f) into main (5b99bd9) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #184   +/-   ##
=======================================
  Coverage   97.14%   97.14%           
=======================================
  Files           9        9           
  Lines        1609     1609           
  Branches      347      347           
=======================================
  Hits         1563     1563           
  Misses         24       24           
  Partials       22       22           
Flag Coverage Δ
unittests 97.14% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

codecov[bot] avatar Apr 19 '22 12:04 codecov[bot]

cyaml__read_bool isn't called unless there is an actual value in the YAML to decode.

The bit representation for any unset optional field is always 0. So for numbers it's zero, pointer are NULL and a character string is the empty string "\0". For a boolean it is false.

tlsa avatar Apr 19 '22 12:04 tlsa

cyaml__read_bool isn't called unless there is an actual value in the YAML to decode.

The bit representation for any unset optional field is always 0. So for numbers it's zero, pointer are NULL and a character string is the empty string "\0". For a boolean it is false.

Yeah, I understand why that is, but when I first looked to see the answer it seemed like cyaml__read_bool would be relevant. Either way it's reasonable to test it (maybe one day in the future it'll rightly fail on some futuristic platform where (int)true is 0 :smile:).

FortStatement avatar Apr 19 '22 12:04 FortStatement