Debian Codegraph @

eutils/transmute_test.go

raw
1 package eutils
2
3 import "testing"
4
5 func stringTestTransmute(t *testing.T, name string, proc func(string) string, input, expected string) {
6
7 actual := proc(input)
8 if actual != expected {
9 t.Errorf("%s(%s) = %s, expected %s", name, input, actual, expected)
10 }
11 }
12
13 func TestJSONtoXML(t *testing.T) {
14
15 stringTestTransmute(t, "JSONtoXML,",
16 func(str string) string { return JSONtoXML(str, "", "Rec", "") },
17 `{"download":"*","collection":"pathway","where":{"ands":[{"geneid":"1956"}]},"order":["taxname,asc"],
18 "start":1,"limit":10000000,"downloadfilename":"GeneID_1956_pathway"}`,
19 `<Rec>
20 <download>*</download>
21 <collection>pathway</collection>
22 <where>
23 <ands>
24 <geneid>1956</geneid>
25 </ands>
26 </where>
27 <order>taxname,asc</order>
28 <start>1</start>
29 <limit>10000000</limit>
30 <downloadfilename>GeneID_1956_pathway</downloadfilename>
31 </Rec>
32 `,
33 )
34 }
35
36 func TestASNtoXML(t *testing.T) {
37
38 stringTestTransmute(t, "ASNtoXML,",
39 func(str string) string { return ASNtoXML(str, "", "") },
40 `Seq-align ::= {
41 segs denseg {
42 numseg 3,
43 ids { genbank { accession "AY046051", version 1 } },
44 starts { 5613, 842, -1, 961, 5599, 962 },
45 lens { 119, 1, 14 },
46 strands { minus, plus, minus, plus, minus, plus }
47 }
48 }
49 `,
50 `<Seq-align>
51 <segs>
52 <denseg>
53 <numseg>3</numseg>
54 <ids>
55 <genbank>
56 <accession>AY046051</accession>
57 <version>1</version>
58 </genbank>
59 </ids>
60 <starts>
61 <starts_E>5613</starts_E>
62 <starts_E>842</starts_E>
63 <starts_E>-1</starts_E>
64 <starts_E>961</starts_E>
65 <starts_E>5599</starts_E>
66 <starts_E>962</starts_E>
67 </starts>
68 <lens>
69 <lens_E>119</lens_E>
70 <lens_E>1</lens_E>
71 <lens_E>14</lens_E>
72 </lens>
73 <strands>
74 <strands_E>minus</strands_E>
75 <strands_E>plus</strands_E>
76 <strands_E>minus</strands_E>
77 <strands_E>plus</strands_E>
78 <strands_E>minus</strands_E>
79 <strands_E>plus</strands_E>
80 </strands>
81 </denseg>
82 </segs>
83 </Seq-align>
84 `,
85 )
86 }
87
88 func TestINItoXML(t *testing.T) {
89
90 stringTestTransmute(t, "INItoXML,",
91 func(str string) string { return INItoXML(str) },
92 `[section1]
93 key1 = value1
94 key2 = value2
95
96 [section2]
97 key3 = value3
98
99 [.sub1]
100 key4 = value4
101
102 [section3.sub1]
103 key5 = value5
104
105 [section3.sub2]
106 key6 = value6
107 `,
108 `<ConfigFile>
109 <section1>
110 <key1>value1</key1>
111 <key2>value2</key2>
112 </section1>
113 <section2>
114 <key3>value3</key3>
115 <sub1>
116 <key4>value4</key4>
117 </sub1>
118 </section2>
119 <section3>
120 <sub1>
121 <key5>value5</key5>
122 </sub1>
123 <sub2>
124 <key6>value6</key6>
125 </sub2>
126 </section3>
127 </ConfigFile>
128 `,
129 )
130 }
131
132 func TestTOMLtoXML(t *testing.T) {
133
134 stringTestTransmute(t, "TOMLtoXML,",
135 func(str string) string { return TOMLtoXML(str) },
136 `[section1]
137 key1 = "value1"
138 key2 = "value2"
139
140 [section2]
141 key3 = "value3"
142
143 [section2.sub1]
144 key4 = "value4"
145
146 [section3.sub1]
147 key5 = "value5"
148
149 [section3.sub2]
150 key6 = "value6"
151 `,
152 `<ConfigFile>
153 <section1>
154 <key1>value1</key1>
155 <key2>value2</key2>
156 </section1>
157 <section2>
158 <key3>value3</key3>
159 <sub1>
160 <key4>value4</key4>
161 </sub1>
162 </section2>
163 <section3>
164 <sub1>
165 <key5>value5</key5>
166 </sub1>
167 <sub2>
168 <key6>value6</key6>
169 </sub2>
170 </section3>
171 </ConfigFile>
172 `,
173 )
174 }
175
176 func TestYAMLtoXML(t *testing.T) {
177
178 stringTestTransmute(t, "YAMLtoXML,",
179 func(str string) string { return YAMLtoXML(str) },
180 `section1:
181 key1: value1
182 key2: value2
183 section2:
184 key3: value3
185 `,
186 `<ConfigFile>
187 <section1>
188 <key1>value1</key1>
189 <key2>value2</key2>
190 </section1>
191 <section2>
192 <key3>value3</key3>
193 </section2>
194 </ConfigFile>
195 `,
196 )
197 }
198
199 func TestNormalizeXML(t *testing.T) {
200
201 stringTestTransmute(t, "NormalizeXML,",
202 func(str string) string {
203 chn := StringToChan(str)
204 rdr := CreateXMLStreamer(nil, chn)
205 nrm := NormalizeXML(rdr, "pubmed")
206 return ChanToString(nrm)
207 },
208 `<DocumentSummary uid="2539356">
209 <PubDate>1989 Apr</PubDate>
210 <Source>J Bacteriol</Source>
211 </DocumentSummary>
212 `,
213 `<DocumentSummary>
214 <Id>
215 2539356
216 </Id>
217 <PubDate>
218 1989 Apr
219 </PubDate>
220 <Source>
221 J Bacteriol
222 </Source>
223 </DocumentSummary>
224 `,
225 )
226 }
227
228 func TestFormatXML(t *testing.T) {
229
230 stringTestTransmute(t, "FormatXML,",
231 func(str string) string {
232 chn := StringToChan(str)
233 rdr := CreateXMLStreamer(nil, chn)
234 tknq := CreateTokenizer(rdr)
235 frgs := FormatArgs{Format: "indent", XML: "", Doctype: ""}
236 frm := FormatTokens(tknq, frgs)
237 return ChanToString(frm)
238 },
239 `<DocumentSummary>
240 <Id>
241 2539356
242 </Id>
243 <PubDate>
244 1989 Apr
245 </PubDate>
246 <Source>
247 J Bacteriol
248 </Source>
249 </DocumentSummary>
250 `,
251 `<?xml version="1.0" encoding="UTF-8" ?>
252 <!DOCTYPE DocumentSummary>
253 <DocumentSummary>
254 <Id>2539356</Id>
255 <PubDate>1989 Apr</PubDate>
256 <Source>J Bacteriol</Source>
257 </DocumentSummary>
258 `,
259 )
260 }