Skip to content
Snippets Groups Projects
Commit 6f93deba authored by Neil Pankey's avatar Neil Pankey
Browse files

test: generate utf-16 testdata and bom variants

parent 6077a84c
No related branches found
No related tags found
No related merge requests found
Showing
with 86 additions and 30 deletions
// +build ignore
// generates clones the utf-8 tests data to the other
// unicode encodings and adds BOM variants of each.
package main
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/unicode"
)
func main() {
var xforms = []struct {
dir, bom string
enc encoding.Encoding
} {
{ "testdata/utf-16be", "\xFE\xFF", unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM) },
{ "testdata/utf-16le", "\xFF\xFE", unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM) },
}
paths, _ := filepath.Glob("testdata/utf-8/*")
for _, p := range paths {
src, err := ioutil.ReadFile(p)
if err != nil {
log.Fatal(err)
}
write("testdata/utf-8_bom", p, "\xEF\xBB\xBF", src)
for _, xform := range xforms {
dst, err := xform.enc.NewEncoder().Bytes(src)
if err != nil {
log.Fatal(err)
}
write(xform.dir, p, "", dst)
write(xform.dir + "_bom", p, xform.bom, dst)
}
}
}
func write(dir, orig, bom string, buf []byte) {
f, err := os.Create(filepath.Join(dir, filepath.Base(orig)))
if err != nil {
log.Fatal(err)
}
if _, err = f.Write([]byte(bom)); err != nil {
log.Fatal(err)
}
if _, err = f.Write(buf); err != nil {
log.Fatal(err)
}
}
...@@ -14,56 +14,56 @@ func TestMain(t *testing.T) { ...@@ -14,56 +14,56 @@ func TestMain(t *testing.T) {
exit int exit int
}{ }{
{ {
"-s testdata/schema.yml testdata/data-pass.yml", "-s testdata/utf-8/schema.yml testdata/utf-8/data-pass.yml",
[]string{"testdata/data-pass.yml: pass"}, []string{"testdata/utf-8/data-pass.yml: pass"},
0, 0,
}, { }, {
"-s testdata/schema.json testdata/data-pass.yml", "-s testdata/utf-8/schema.json testdata/utf-8/data-pass.yml",
[]string{"testdata/data-pass.yml: pass"}, []string{"testdata/utf-8/data-pass.yml: pass"},
0, 0,
}, { }, {
"-s testdata/schema.json testdata/data-pass.json", "-s testdata/utf-8/schema.json testdata/utf-8/data-pass.json",
[]string{"testdata/data-pass.json: pass"}, []string{"testdata/utf-8/data-pass.json: pass"},
0, 0,
}, { }, {
"-s testdata/schema.yml testdata/data-pass.json", "-s testdata/utf-8/schema.yml testdata/utf-8/data-pass.json",
[]string{"testdata/data-pass.json: pass"}, []string{"testdata/utf-8/data-pass.json: pass"},
0, 0,
}, { }, {
"-q -s testdata/schema.yml testdata/data-fail.yml", "-q -s testdata/utf-8/schema.yml testdata/utf-8/data-fail.yml",
[]string{"testdata/data-fail.yml: fail: (root): foo is required"}, []string{"testdata/utf-8/data-fail.yml: fail: (root): foo is required"},
1, 1,
}, { }, {
"-q -s testdata/schema.json testdata/data-fail.yml", "-q -s testdata/utf-8/schema.json testdata/utf-8/data-fail.yml",
[]string{"testdata/data-fail.yml: fail: (root): foo is required"}, []string{"testdata/utf-8/data-fail.yml: fail: (root): foo is required"},
1, 1,
}, { }, {
"-q -s testdata/schema.json testdata/data-fail.json", "-q -s testdata/utf-8/schema.json testdata/utf-8/data-fail.json",
[]string{"testdata/data-fail.json: fail: (root): foo is required"}, []string{"testdata/utf-8/data-fail.json: fail: (root): foo is required"},
1, 1,
}, { }, {
"-q -s testdata/schema.yml testdata/data-fail.json", "-q -s testdata/utf-8/schema.yml testdata/utf-8/data-fail.json",
[]string{"testdata/data-fail.json: fail: (root): foo is required"}, []string{"testdata/utf-8/data-fail.json: fail: (root): foo is required"},
1, 1,
}, { }, {
"-q -s testdata/schema.json testdata/data-error.json", "-q -s testdata/utf-8/schema.json testdata/utf-8/data-error.json",
[]string{"testdata/data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')"}, []string{"testdata/utf-8/data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')"},
2, 2,
}, { }, {
"-q -s testdata/schema.yml testdata/data-error.yml", "-q -s testdata/utf-8/schema.yml testdata/utf-8/data-error.yml",
[]string{"testdata/data-error.yml: error: load doc: yaml: found unexpected end of stream"}, []string{"testdata/utf-8/data-error.yml: error: load doc: yaml: found unexpected end of stream"},
2, 2,
}, { }, {
"-q -s testdata/schema.json testdata/data-*.json", "-q -s testdata/utf-8/schema.json testdata/utf-8/data-*.json",
[]string{ []string{
"testdata/data-fail.json: fail: (root): foo is required", "testdata/utf-8/data-fail.json: fail: (root): foo is required",
"testdata/data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')", "testdata/utf-8/data-error.json: error: validate: invalid character 'o' in literal null (expecting 'u')",
}, 3, }, 3,
}, { }, {
"-q -s testdata/schema.yml testdata/data-*.yml", "-q -s testdata/utf-8/schema.yml testdata/utf-8/data-*.yml",
[]string{ []string{
"testdata/data-error.yml: error: load doc: yaml: found unexpected end of stream", "testdata/utf-8/data-error.yml: error: load doc: yaml: found unexpected end of stream",
"testdata/data-fail.yml: fail: (root): foo is required", "testdata/utf-8/data-fail.yml: fail: (root): foo is required",
}, 3, }, 3,
}, },
} }
...@@ -89,4 +89,3 @@ func TestMain(t *testing.T) { ...@@ -89,4 +89,3 @@ func TestMain(t *testing.T) {
}) })
} }
} }
File added
File added
File added
File added
File added
File added
File added
File added
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment