3 #load "netstring.cma";;
7 (**********************************************************************)
8 (* scan_structured_value *)
9 (**********************************************************************)
12 let r = scan_structured_value "user@domain.com" [ '@'; '.' ] [] in
13 r = [ Atom "user"; Special '@'; Atom "domain"; Special '.'; Atom "com" ]
18 let r = scan_structured_value "user @ domain . com" [ '@'; '.' ] [] in
19 r = [ Atom "user"; Special '@'; Atom "domain"; Special '.'; Atom "com" ]
24 let r = scan_structured_value "user(Do you know him?)@domain.com" [ '@'; '.' ]
26 r = [ Atom "user"; Special '@'; Atom "domain"; Special '.'; Atom "com" ]
31 let r = scan_structured_value "user @ domain . com" [ '@'; '.'; ' ' ] [] in
32 r = [ Atom "user"; Special ' '; Special '@'; Special ' '; Atom "domain";
33 Special ' '; Special '.'; Special ' '; Atom "com" ]
38 let r = scan_structured_value "user(Do you know him?)@domain.com"
40 r = [ Atom "user"; Special '('; Atom "Do"; Atom "you"; Atom "know";
41 Atom "him?)"; Special '@'; Atom "domain"; Special '.'; Atom "com" ]
46 let r = scan_structured_value "\"My.name\"@domain.com" [ '@'; '.' ] [] in
47 r = [ QString "My.name"; Special '@'; Atom "domain"; Special '.';
53 let r = scan_structured_value "\"\\\"()@. \"@domain.com" [ '@'; '.' ] [] in
54 r = [ QString "\"()@. "; Special '@'; Atom "domain"; Special '.';
60 let r = scan_structured_value "a(b(c(d)e)f)g" [] [] in
61 r = [ Atom "a"; Atom "g" ]
66 let r = scan_structured_value "a(b(c(d)e)f" [] [] in
72 let r = scan_structured_value "a(b\\(c\\(d\\)e)f" [] [] in
73 r = [ Atom "a"; Atom "f" ]
78 let r = scan_structured_value "a(b(c(d)e)f\\" [] [] in
84 let r = scan_structured_value "\"abc" [] [] in
90 let r = scan_structured_value "\"abc\\" [] [] in
91 r = [ QString "abc\\" ]
95 (* New tests for netstring-0.9: *)
98 let r = scan_structured_value "user(Do you know him?)@domain.com"
99 [ '@'; '.' ] [ Return_comments ] in
100 r = [ Atom "user"; Comment; Special '@'; Atom "domain"; Special '.';
105 let r = scan_structured_value "user (Do you know him?) @ domain . com"
106 [ '@'; '.'; ' ' ] [] in
107 r = [ Atom "user"; Special ' '; Special ' '; Special ' '; Special '@';
108 Special ' '; Atom "domain";
109 Special ' '; Special '.'; Special ' '; Atom "com" ]
113 let r = scan_structured_value "user (Do you know him?) @ domain . com"
114 [ '@'; '.'; ' ' ] [ Return_comments ] in
115 r = [ Atom "user"; Special ' '; Comment; Special ' '; Special '@';
116 Special ' '; Atom "domain";
117 Special ' '; Special '.'; Special ' '; Atom "com" ]
121 let r = scan_structured_value "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?="
123 r = [ Atom "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?=" ]
127 let r = scan_structured_value "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?="
128 [ ] [ Recognize_encoded_words ] in
129 r = [ EncodedWord("ISO-8859-1", "Q", "Keld_J=F8rn_Simonsen") ]
133 let r = scan_structured_value
134 "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?="
136 [ Recognize_encoded_words ] in
138 ("ISO-8859-1", "B", "SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=");
140 ("ISO-8859-2", "B", "dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==")
144 (**********************************************************************)
145 (* s_extended_token *)
146 (**********************************************************************)
148 let scan specials options str =
149 let scn = create_mime_scanner specials options str in
150 scan_token_list scn;;
153 let r = scan [] [] "Two atoms" in
155 [ a1, Atom "Two"; a2, Atom "atoms" ] ->
159 (get_column a1 = 0) &&
160 (get_length a1 = 3) &&
161 (separates_adjacent_encoded_words a1 = false) &&
165 (get_column a2 = 4) &&
166 (get_length a2 = 5) &&
167 (separates_adjacent_encoded_words a2 = false)
175 let r = scan [] [] " Two atoms " in
177 [ a1, Atom "Two"; a2, Atom "atoms" ] ->
181 (get_column a1 = 2) &&
182 (get_length a1 = 3) &&
183 (separates_adjacent_encoded_words a1 = false) &&
187 (get_column a2 = 7) &&
188 (get_length a2 = 5) &&
189 (separates_adjacent_encoded_words a2 = false)
197 let r = scan [] [] " Two\n atoms " in
199 [ a1, Atom "Two"; a2, Atom "atoms" ] ->
203 (get_column a1 = 2) &&
204 (get_length a1 = 3) &&
205 (separates_adjacent_encoded_words a1 = false) &&
209 (get_column a2 = 1) &&
210 (get_length a2 = 5) &&
211 (separates_adjacent_encoded_words a2 = false)
218 let r = scan [] [] "\"Two\" \"qstrings\"" in
220 [ a1, QString "Two"; a2, QString "qstrings" ] ->
224 (get_column a1 = 0) &&
225 (get_length a1 = 5) &&
226 (separates_adjacent_encoded_words a1 = false) &&
230 (get_column a2 = 6) &&
231 (get_length a2 = 10) &&
232 (separates_adjacent_encoded_words a2 = false)
239 let r = scan [] [] " \"Two\" \"qstrings\" " in
241 [ a1, QString "Two"; a2, QString "qstrings" ] ->
245 (get_column a1 = 2) &&
246 (get_length a1 = 5) &&
247 (separates_adjacent_encoded_words a1 = false) &&
251 (get_column a2 = 9) &&
252 (get_length a2 = 10) &&
253 (separates_adjacent_encoded_words a2 = false)
260 let r = scan [] [] " \"Two\nlines\" \"and\nqstrings\" " in
262 [ a1, QString "Two\nlines"; a2, QString "and\nqstrings" ] ->
266 (get_column a1 = 2) &&
267 (get_length a1 = 11) &&
268 (separates_adjacent_encoded_words a1 = false) &&
272 (get_column a2 = 8) &&
273 (get_length a2 = 14) &&
274 (separates_adjacent_encoded_words a2 = false)
281 let r = scan [] [] " \"Two\\\nlines\" \"and\\\nqstrings\" " in
283 [ a1, QString "Two\nlines"; a2, QString "and\nqstrings" ] ->
287 (get_column a1 = 2) &&
288 (get_length a1 = 12) &&
289 (separates_adjacent_encoded_words a1 = false) &&
293 (get_column a2 = 8) &&
294 (get_length a2 = 15) &&
295 (separates_adjacent_encoded_words a2 = false)
302 (* Domain literals are implemented like quoted strings, so only the
303 * most complicated test case.
305 let r = scan [] [] " [Two\\\nlines] [and\\\nliterals] " in
307 [ a1, DomainLiteral "Two\nlines"; a2, DomainLiteral "and\nliterals" ] ->
311 (get_column a1 = 2) &&
312 (get_length a1 = 12) &&
313 (separates_adjacent_encoded_words a1 = false) &&
317 (get_column a2 = 8) &&
318 (get_length a2 = 15) &&
319 (separates_adjacent_encoded_words a2 = false)
326 let r = scan [] [ Return_comments ] "(Two) (comments)" in
328 [ a1, Comment; a2, Comment ] ->
332 (get_column a1 = 0) &&
333 (get_length a1 = 5) &&
334 (separates_adjacent_encoded_words a1 = false) &&
338 (get_column a2 = 6) &&
339 (get_length a2 = 10) &&
340 (separates_adjacent_encoded_words a2 = false)
347 let r = scan [] [ Return_comments ] "(Two\nlines) (and\ncomments)" in
349 [ a1, Comment; a2, Comment ] ->
353 (get_column a1 = 0) &&
354 (get_length a1 = 11) &&
355 (separates_adjacent_encoded_words a1 = false) &&
359 (get_column a2 = 7) &&
360 (get_length a2 = 14) &&
361 (separates_adjacent_encoded_words a2 = false)
368 let r = scan [] [ Return_comments ] "(Two\\\nlines) (and\\\ncomments)" in
370 [ a1, Comment; a2, Comment ] ->
374 (get_column a1 = 0) &&
375 (get_length a1 = 12) &&
376 (separates_adjacent_encoded_words a1 = false) &&
380 (get_column a2 = 7) &&
381 (get_length a2 = 15) &&
382 (separates_adjacent_encoded_words a2 = false)
389 let r = scan [] [ Return_comments ] "(a\n(b\nc)d\ne(f)) atom" in
391 [ a1, Comment; a2, Atom "atom" ] ->
395 (get_column a1 = 0) &&
396 (get_length a1 = 15) &&
397 (separates_adjacent_encoded_words a1 = false) &&
401 (get_column a2 = 6) &&
402 (get_length a2 = 4) &&
403 (separates_adjacent_encoded_words a2 = false)
410 let r = scan [] [] "\031\031" in
412 [ a1, Control '\031'; a2, Control '\031' ] ->
416 (get_column a1 = 0) &&
417 (get_length a1 = 1) &&
418 (separates_adjacent_encoded_words a1 = false) &&
422 (get_column a2 = 1) &&
423 (get_length a2 = 1) &&
424 (separates_adjacent_encoded_words a2 = false)
431 let r = scan [ '\t'; '\n' ] [] " \t\n \n \t" in
433 [ a1, Special '\t'; _, Special '\n'; _, Special '\n'; a2, Special '\t'] ->
437 (get_column a1 = 1) &&
438 (get_length a1 = 1) &&
439 (separates_adjacent_encoded_words a1 = false) &&
443 (get_column a2 = 2) &&
444 (get_length a2 = 1) &&
445 (separates_adjacent_encoded_words a2 = false)
452 let r = scan [] [ Recognize_encoded_words ]
453 "=?iso8859-1?q?G=F6rd?= =?iso8859-1?q?G=F6rd?=" in
455 [ a1, EncodedWord("ISO8859-1", "Q", "G=F6rd");
456 a2, EncodedWord("ISO8859-1", "Q", "G=F6rd"); ] ->
460 (get_column a1 = 0) &&
461 (get_length a1 = 22) &&
462 (separates_adjacent_encoded_words a1 = false) &&
463 (get_decoded_word a1 = "Görd") &&
464 (get_charset a1 = "ISO8859-1") &&
468 (get_column a2 = 23) &&
469 (get_length a2 = 22) &&
470 (separates_adjacent_encoded_words a2 = false) &&
471 (get_decoded_word a2 = "Görd") &&
472 (get_charset a2 = "ISO8859-1")
479 let r = scan [ ' ' ] [ Recognize_encoded_words ]
480 "=?iso8859-1?q?G=F6rd?= =?iso8859-1?q?G=F6rd?=" in
482 [ a1, EncodedWord("ISO8859-1", "Q", "G=F6rd");
484 a2, EncodedWord("ISO8859-1", "Q", "G=F6rd"); ] ->
488 (get_column a1 = 0) &&
489 (get_length a1 = 22) &&
490 (separates_adjacent_encoded_words a1 = false) &&
491 (get_decoded_word a1 = "Görd") &&
492 (get_charset a1 = "ISO8859-1") &&
496 (get_column a2 = 23) &&
497 (get_length a2 = 22) &&
498 (separates_adjacent_encoded_words a2 = false) &&
499 (get_decoded_word a2 = "Görd") &&
500 (get_charset a2 = "ISO8859-1") &&
502 (separates_adjacent_encoded_words sp = true)
509 let r = scan [ ' ' ] [ Recognize_encoded_words ]
510 "=?iso8859-1?q?G=F6rd?= =?iso8859-1?q?G=F6rd?=" in
512 [ a1, EncodedWord("ISO8859-1", "Q", "G=F6rd");
515 a2, EncodedWord("ISO8859-1", "Q", "G=F6rd"); ] ->
519 (get_column a1 = 0) &&
520 (get_length a1 = 22) &&
521 (separates_adjacent_encoded_words a1 = false) &&
522 (get_decoded_word a1 = "Görd") &&
523 (get_charset a1 = "ISO8859-1") &&
527 (get_column a2 = 24) &&
528 (get_length a2 = 22) &&
529 (separates_adjacent_encoded_words a2 = false) &&
530 (get_decoded_word a2 = "Görd") &&
531 (get_charset a2 = "ISO8859-1") &&
533 (separates_adjacent_encoded_words sp1 = true) &&
534 (separates_adjacent_encoded_words sp2 = true)
542 (**********************************************************************)
546 print_endline ("Test " ^ n ^ " ok")
548 print_endline ("Test " ^ n ^ " FAILED!!!!");