Skip to content

Commit

Permalink
test: Add test for float scalar key-value pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed Apr 28, 2022
1 parent c872e9e commit 9c91e0d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 31 deletions.
64 changes: 33 additions & 31 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ specification defined below.
- [-] Scalar
- [X] Boolean
- [X] Integer
- [X] Float
- [ ] String
- [ ] Float
- [ ] Date + Time with Offset
- [ ] Date
- [ ] Nil
Expand Down Expand Up @@ -104,29 +104,8 @@ int4 = -17
: "int3": 0,
: "int4": -17
: }
*** String
https://toml.io/en/v1.0.0#string
**** S-expression
#+begin_src emacs-lisp :eval no :noweb-ref scalar-string
'((str . "Roses are red\nViolets are blue"))
#+end_src
**** TOML
#+begin_src toml
str = """
Roses are red
Violets are blue"""
#+end_src
**** JSON Reference
#+begin_src emacs-lisp :noweb yes :exports results
(json-encode-pretty
<<scalar-string>>)
#+end_src

#+RESULTS:
: {
: "str": "Roses are red\nViolets are blue"
: }
*** Float
*** DONE Float
CLOSED: [2022-04-28 Thu 17:29]
https://toml.io/en/v1.0.0#float
**** S-expression
#+begin_src emacs-lisp :eval no :noweb-ref scalar-float
Expand All @@ -139,18 +118,19 @@ https://toml.io/en/v1.0.0#float
(flt7 . 6.626e-34))
#+end_src
**** TOML
#+begin_src emacs-lisp :noweb yes :exports results :wrap src toml
(tomelr-encode
<<scalar-float>>)
#+end_src

#+RESULTS:
#+begin_src toml
# fractional
flt1 = 1.0
flt2 = 3.1415
flt3 = -0.01

# exponent
flt4 = 5e+22
flt5 = 1e06
flt6 = -2E-2

# both
flt5 = 1000000.0
flt6 = -0.02
flt7 = 6.626e-34
#+end_src
**** JSON Reference
Expand All @@ -169,6 +149,28 @@ flt7 = 6.626e-34
: "flt6": -0.02,
: "flt7": 6.626e-34
: }
*** String
https://toml.io/en/v1.0.0#string
**** S-expression
#+begin_src emacs-lisp :eval no :noweb-ref scalar-string
'((str . "Roses are red\nViolets are blue"))
#+end_src
**** TOML
#+begin_src toml
str = """
Roses are red
Violets are blue"""
#+end_src
**** JSON Reference
#+begin_src emacs-lisp :noweb yes :exports results
(json-encode-pretty
<<scalar-string>>)
#+end_src

#+RESULTS:
: {
: "str": "Roses are red\nViolets are blue"
: }
*** Date + Time with Offset
https://toml.io/en/v1.0.0#offset-date-time
**** S-expression
Expand Down
21 changes: 21 additions & 0 deletions test/tscalar.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,26 @@
(push (tomelr-encode el) out))
(should (equal ref (nreverse out)))))

;;;; Scalar - Float
(ert-deftest test-scalar-float ()
(let ((inp '(((float1 . +1.0))
((float2 . 3.1415))
((float3 . -0.01))
((float4 . 5e+22))
((float5 . 1e06))
((float6 . -2E-2))
((float7 . 6.626e-34))))
(ref '("float1 = 1.0"
"float2 = 3.1415"
"float3 = -0.01"
"float4 = 5e+22"
"float5 = 1000000.0"
"float6 = -0.02"
"float7 = 6.626e-34"))
out)
(dolist (el inp)
(push (tomelr-encode el) out))
(should (equal ref (nreverse out)))))


(provide 'tscalar)

0 comments on commit 9c91e0d

Please sign in to comment.