forked from MathieuTurcotte/sourcemap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_test.go
59 lines (49 loc) · 1.5 KB
/
read_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2013 Mathieu Turcotte
// Licensed under the MIT license.
package sourcemap
import (
"encoding/json"
"os"
"reflect"
"testing"
)
func TestRead(t *testing.T) {
cases := []struct {
sourceMapPath string
serializedSourceMapPath string
}{
{"testdata/sample.sourcemap", "testdata/sample.json"},
}
for _, c := range cases {
testRead(t, c.sourceMapPath, c.serializedSourceMapPath)
}
}
func testRead(t *testing.T, sourceMapPath, serializedSourceMapPath string) {
var decodedSourceMap SourceMap
var serializedSourceMap SourceMap
// Read the serialized source map.
serializedSourceMapFile, err := os.Open(serializedSourceMapPath)
if err != nil {
t.Fatalf("could not open serialized source map: %s", err)
}
defer serializedSourceMapFile.Close()
dec := json.NewDecoder(serializedSourceMapFile)
if err := dec.Decode(&serializedSourceMap); err != nil {
t.Fatalf("could not open serialized source map: %s", err)
}
// Read the source map to decode.
sourceMapFile, err := os.Open(sourceMapPath)
if err != nil {
t.Fatalf("could not open serialized source map: %s", err)
}
defer sourceMapFile.Close()
decodedSourceMap, err = Read(sourceMapFile)
if err != nil {
t.Errorf("unexpected error when decoding source map: %s", err)
}
if !reflect.DeepEqual(decodedSourceMap, serializedSourceMap) {
t.Errorf("decoded source map doesn't match serialized source map")
t.Errorf("decoded source map: %+v", decodedSourceMap)
t.Errorf("serialized source map: %+v", serializedSourceMap)
}
}