~ehmry/dhall-nim

db645e16cb5cc9789ba209ca019292dd61fb64aa — Emery Hemingway 1 year, 1 month ago 73cdb33
binary: add decodeFile
2 files changed, 13 insertions(+), 6 deletions(-)

M src/dhall/binary.nim
M tests/test1.nim
M src/dhall/binary.nim => src/dhall/binary.nim +5 -0
@@ 484,3 484,8 @@ proc decode*(str: Stream): Term =

proc decode*(buf: string): Term =
  buf.newStringStream.decode

proc decodeFile*(path: string): Term =
  let str = newFileStream(path)
  defer: close str
  decode str

M tests/test1.nim => tests/test1.nim +8 -6
@@ 43,13 43,15 @@ suite "binary-decode":
    let testDir = "dhall-lang/tests/binary-decode/success"
    for testBase in dhallTests(testDir, "A.dhallb"):
      test "success" / testBase:
        checkpoint(readFile(testDir / testBase & "A.diag"))
        let
          data = readFile(testDir / testBase & "A.dhallb")
          term = decode data
          cbor = encode term
          roundtrip = decode cbor
        check(not roundtrip.isNil)
          txt = readFile(testDir / testBase & "B.dhall")
          diag = readFile(testDir / testBase & "A.diag")
        checkpoint(txt)
        checkpoint(diag)
        let
          termBin = decodeFile(testDir / testBase & "A.dhallb")
          termTxt = parse txt
        check(termTxt.encode == termBin.encode)
  block failure:
    let testDir = "dhall-lang/tests/binary-decode/failure"
    for testBase in dhallTests(testDir, ".dhallb"):