Debian Codegraph @

jcs_test.go

raw symbols SCIP
1 // Copyright 2021 Bret Jordan & Benedikt Thoma, All rights reserved.
2 // Copyright 2006-2019 WebPKI.org (http://webpki.org).
3 //
4 // Use of this source code is governed by an Apache 2.0 license that can be
5 // found in the LICENSE file in the root of the source tree.
6
7 package jcsscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/
8
9 import (
10 "bytesscip-go gomod github.com/golang/go/src go1.15 bytes/"
11 "fmtscip-go gomod github.com/golang/go/src go1.15 fmt/"
12 "osscip-go gomod github.com/golang/go/src go1.15 os/"
13 "path/filepathscip-go gomod github.com/golang/go/src go1.15 `path/filepath`/"
14 "testingscip-go gomod github.com/golang/go/src go1.15 testing/"
15
16 "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/"
17 )
18
19 const (
20 pathTestDatascip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/pathTestData. = "./testdata"
21 pathInputRelativeToTestDatascip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/pathInputRelativeToTestData. = "/input"
22 pathOutputRelativeToTestDatascip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/pathOutputRelativeToTestData. = "/output"
23 )
24
25 func failedBecausescip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/failedBecause().(errormsg string) string {
26 return fmtscip-go gomod github.com/golang/go/src go1.15 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.15 fmt/Sprintf().("Failed because %s", errormsg)
27 }
28
29 func errorOccurredscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/errorOccurred().(activity string, err error) string {
30 return failedBecausescip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/failedBecause().(fmtscip-go gomod github.com/golang/go/src go1.15 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.15 fmt/Sprintf().("an error occurred while %s: %s\n", activity, err))
31 }
32
33 func doesNotMatchExpectedscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/doesNotMatchExpected().(expectedField, expectedValue, actualField, actualValue string) string {
34 return failedBecausescip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/failedBecause().(
35 fmtscip-go gomod github.com/golang/go/src go1.15 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.15 fmt/Sprintf().(
36 "%s [%s] does not match expected %s [%s]\n",
37 actualField,
38 actualValue,
39 expectedField,
40 expectedValue,
41 ),
42 )
43 }
44
45 func TestTransformscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/TestTransform().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) {
46 testCases := []struct {
47 desc string
48 filename string
49 }{
50 {
51 desc: "Null",
52 filename: "null.json",
53 },
54 {
55 desc: "True",
56 filename: "true.json",
57 },
58 {
59 desc: "False",
60 filename: "false.json",
61 },
62 {
63 desc: "Arrays",
64 filename: "arrays.json",
65 },
66 {
67 desc: "French",
68 filename: "french.json",
69 },
70 {
71 desc: "SimpleString",
72 filename: "simpleString.json",
73 },
74 {
75 desc: "Structures",
76 filename: "structures.json",
77 },
78 {
79 desc: "Unicode",
80 filename: "unicode.json",
81 },
82 {
83 desc: "Values",
84 filename: "values.json",
85 },
86 {
87 desc: "Weird",
88 filename: "weird.json",
89 },
90 }
91 for _, tC := range testCases {
92 t.Runscip-go gomod github.com/golang/go/src go1.15 testing/T#Run().(tC.desc, func(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) {
93 tC := tC
94 t.Parallelscip-go gomod github.com/golang/go/src go1.15 testing/T#Parallel().()
95 r := requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/New().(t)
96
97 input, err := osscip-go gomod github.com/golang/go/src go1.15 os/.ReadFilescip-go gomod github.com/golang/go/src go1.15 os/ReadFile().(filepathscip-go gomod github.com/golang/go/src go1.15 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.15 `path/filepath`/Join().(pathTestDatascip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/pathTestData.,
98 pathInputRelativeToTestDatascip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/pathInputRelativeToTestData., tC.filename))
99 r.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err, errorOccurredscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/errorOccurred().("reading test input json", err))
100
101 output, err := osscip-go gomod github.com/golang/go/src go1.15 os/.ReadFilescip-go gomod github.com/golang/go/src go1.15 os/ReadFile().(filepathscip-go gomod github.com/golang/go/src go1.15 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.15 `path/filepath`/Join().(pathTestDatascip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/pathTestData.,
102 pathOutputRelativeToTestDatascip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/pathOutputRelativeToTestData., tC.filename))
103 r.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err, errorOccurredscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/errorOccurred().("reading expected transformed output sample", err))
104
105 transformed, err := Transformscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/Transform().(input)
106 r.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err, errorOccurredscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/errorOccurred().("transforming test input", err))
107
108 twiceTransformed, err := Transformscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/Transform().(input)
109 r.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#NoError().(err, errorOccurredscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/errorOccurred().("transforming transformed input", err))
110
111 r.Truescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#True().(
112 bytesscip-go gomod github.com/golang/go/src go1.15 bytes/.Equalscip-go gomod github.com/golang/go/src go1.15 bytes/Equal().(transformed, output),
113 doesNotMatchExpectedscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/doesNotMatchExpected().(
114 "JSON",
115 string(output),
116 "transformed JSON",
117 string(transformed),
118 ),
119 )
120 r.Truescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Assertions#True().(
121 bytesscip-go gomod github.com/golang/go/src go1.15 bytes/.Equalscip-go gomod github.com/golang/go/src go1.15 bytes/Equal().(twiceTransformed, transformed),
122 doesNotMatchExpectedscip-go gomod github.com/gowebpki/jcs . `github.com/gowebpki/jcs`/doesNotMatchExpected().(
123 "transformed JSON",
124 string(transformed),
125 "twice transformed JSON",
126 string(twiceTransformed),
127 ),
128 )
129 })
130 }
131 }