package eutils
import "testing"
func stringTestTransmute(t *testing.T, name string, proc func(string) string, input, expected string) {
actual := proc(input)
if actual != expected {
t.Errorf("%s(%s) = %s, expected %s", name, input, actual, expected)
}
}
func TestJSONtoXML(t *testing.T) {
stringTestTransmute(t, "JSONtoXML,",
func(str string) string { return JSONtoXML(str, "", "Rec", "") },
`{"download":"*","collection":"pathway","where":{"ands":[{"geneid":"1956"}]},"order":["taxname,asc"],
"start":1,"limit":10000000,"downloadfilename":"GeneID_1956_pathway"}`,
`
*
pathway
1956
taxname,asc
1
10000000
GeneID_1956_pathway
`,
)
}
func TestASNtoXML(t *testing.T) {
stringTestTransmute(t, "ASNtoXML,",
func(str string) string { return ASNtoXML(str, "", "") },
`Seq-align ::= {
segs denseg {
numseg 3,
ids { genbank { accession "AY046051", version 1 } },
starts { 5613, 842, -1, 961, 5599, 962 },
lens { 119, 1, 14 },
strands { minus, plus, minus, plus, minus, plus }
}
}
`,
`
3
AY046051
1
5613
842
-1
961
5599
962
119
1
14
minus
plus
minus
plus
minus
plus
`,
)
}
func TestINItoXML(t *testing.T) {
stringTestTransmute(t, "INItoXML,",
func(str string) string { return INItoXML(str) },
`[section1]
key1 = value1
key2 = value2
[section2]
key3 = value3
[.sub1]
key4 = value4
[section3.sub1]
key5 = value5
[section3.sub2]
key6 = value6
`,
`
value1
value2
value3
value4
value5
value6
`,
)
}
func TestTOMLtoXML(t *testing.T) {
stringTestTransmute(t, "TOMLtoXML,",
func(str string) string { return TOMLtoXML(str) },
`[section1]
key1 = "value1"
key2 = "value2"
[section2]
key3 = "value3"
[section2.sub1]
key4 = "value4"
[section3.sub1]
key5 = "value5"
[section3.sub2]
key6 = "value6"
`,
`
value1
value2
value3
value4
value5
value6
`,
)
}
func TestYAMLtoXML(t *testing.T) {
stringTestTransmute(t, "YAMLtoXML,",
func(str string) string { return YAMLtoXML(str) },
`section1:
key1: value1
key2: value2
section2:
key3: value3
`,
`
value1
value2
value3
`,
)
}
func TestNormalizeXML(t *testing.T) {
stringTestTransmute(t, "NormalizeXML,",
func(str string) string {
chn := StringToChan(str)
rdr := CreateXMLStreamer(nil, chn)
nrm := NormalizeXML(rdr, "pubmed")
return ChanToString(nrm)
},
`
1989 Apr
J Bacteriol
`,
`
2539356
1989 Apr
J Bacteriol
`,
)
}
func TestFormatXML(t *testing.T) {
stringTestTransmute(t, "FormatXML,",
func(str string) string {
chn := StringToChan(str)
rdr := CreateXMLStreamer(nil, chn)
tknq := CreateTokenizer(rdr)
frgs := FormatArgs{Format: "indent", XML: "", Doctype: ""}
frm := FormatTokens(tknq, frgs)
return ChanToString(frm)
},
`
2539356
1989 Apr
J Bacteriol
`,
`
2539356
1989 Apr
J Bacteriol
`,
)
}