-
Notifications
You must be signed in to change notification settings - Fork 11
/
compact_test.go
44 lines (40 loc) · 1.35 KB
/
compact_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2015 Jean Niklas L'orange. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package edn
import (
"bytes"
"testing"
)
func TestConvert(t *testing.T) {
// basic
checkConvert(t, "foo bar baz", "foo bar baz")
// preserves correct spacing?
checkConvert(t, "a,b\nc\td", "a,b\nc\td")
// removes unnecessary spacing?
checkConvert(t, "a b", "a b")
// Compacts more complex stuff?
checkConvert(t, `{:a "foo", :b zing ,:c 12.3e3}`, `{:a"foo":b zing,:c 12.3e3}`)
// Doesn't compact away discards?
checkConvert(t, `#_=> nil`, `#_=> nil`)
// Removes comments?
checkConvert(t, "; just a comment, I am ignored", "")
checkConvert(t, "foo;; bar\nbaz", "foo\nbaz")
// Doesn't break on delimiters
checkConvert(t, "f(x)", "f(x)")
checkConvert(t, "#a[1]", "#a[1]")
checkConvert(t, "#a #b[1]", "#a #b[1]")
checkConvert(t, "#a #b{:x 1}", "#a #b{:x 1}")
checkConvert(t, "#tag/a{:x 1}", "#tag/a{:x 1}")
}
func checkConvert(t *testing.T, input, expected string) {
var buf bytes.Buffer
err := Compact(&buf, []byte(input))
if err != nil {
t.Errorf("Unexpected error: %s", err.Error())
} else if !bytes.Equal([]byte(expected), buf.Bytes()) {
t.Errorf("Convert received '%s', expected '%s' back, was '%s'",
input, expected, string(buf.Bytes()))
}
buf.Reset()
}