• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::character::is_alphabetic;
2 use crate::character::streaming::{
3   alpha1 as alpha, alphanumeric1 as alphanumeric, digit1 as digit, hex_digit1 as hex_digit,
4   multispace1 as multispace, oct_digit1 as oct_digit, space1 as space,
5 };
6 use crate::error::ErrorKind;
7 use crate::internal::{Err, IResult, Needed};
8 #[cfg(feature = "alloc")]
9 use crate::{
10   branch::alt,
11   bytes::complete::{escaped, escaped_transform, tag},
12   combinator::{map, value},
13   lib::std::string::String,
14   lib::std::vec::Vec,
15 };
16 
17 #[test]
is_a()18 fn is_a() {
19   use crate::bytes::streaming::is_a;
20 
21   fn a_or_b(i: &[u8]) -> IResult<&[u8], &[u8]> {
22     is_a("ab")(i)
23   }
24 
25   let a = &b"abcd"[..];
26   assert_eq!(a_or_b(a), Ok((&b"cd"[..], &b"ab"[..])));
27 
28   let b = &b"bcde"[..];
29   assert_eq!(a_or_b(b), Ok((&b"cde"[..], &b"b"[..])));
30 
31   let c = &b"cdef"[..];
32   assert_eq!(
33     a_or_b(c),
34     Err(Err::Error(error_position!(c, ErrorKind::IsA)))
35   );
36 
37   let d = &b"bacdef"[..];
38   assert_eq!(a_or_b(d), Ok((&b"cdef"[..], &b"ba"[..])));
39 }
40 
41 #[test]
is_not()42 fn is_not() {
43   use crate::bytes::streaming::is_not;
44 
45   fn a_or_b(i: &[u8]) -> IResult<&[u8], &[u8]> {
46     is_not("ab")(i)
47   }
48 
49   let a = &b"cdab"[..];
50   assert_eq!(a_or_b(a), Ok((&b"ab"[..], &b"cd"[..])));
51 
52   let b = &b"cbde"[..];
53   assert_eq!(a_or_b(b), Ok((&b"bde"[..], &b"c"[..])));
54 
55   let c = &b"abab"[..];
56   assert_eq!(
57     a_or_b(c),
58     Err(Err::Error(error_position!(c, ErrorKind::IsNot)))
59   );
60 
61   let d = &b"cdefba"[..];
62   assert_eq!(a_or_b(d), Ok((&b"ba"[..], &b"cdef"[..])));
63 
64   let e = &b"e"[..];
65   assert_eq!(a_or_b(e), Err(Err::Incomplete(Needed::new(1))));
66 }
67 
68 #[cfg(feature = "alloc")]
69 #[allow(unused_variables)]
70 #[test]
escaping()71 fn escaping() {
72   use crate::character::streaming::one_of;
73 
74   fn esc(i: &[u8]) -> IResult<&[u8], &[u8]> {
75     escaped(alpha, '\\', one_of("\"n\\"))(i)
76   }
77   assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], &b"abcd"[..])));
78   assert_eq!(esc(&b"ab\\\"cd;"[..]), Ok((&b";"[..], &b"ab\\\"cd"[..])));
79   assert_eq!(esc(&b"\\\"abcd;"[..]), Ok((&b";"[..], &b"\\\"abcd"[..])));
80   assert_eq!(esc(&b"\\n;"[..]), Ok((&b";"[..], &b"\\n"[..])));
81   assert_eq!(esc(&b"ab\\\"12"[..]), Ok((&b"12"[..], &b"ab\\\""[..])));
82   assert_eq!(
83     esc(&b"AB\\"[..]),
84     Err(Err::Error(error_position!(
85       &b"AB\\"[..],
86       ErrorKind::Escaped
87     )))
88   );
89   assert_eq!(
90     esc(&b"AB\\A"[..]),
91     Err(Err::Error(error_node_position!(
92       &b"AB\\A"[..],
93       ErrorKind::Escaped,
94       error_position!(&b"A"[..], ErrorKind::OneOf)
95     )))
96   );
97 
98   fn esc2(i: &[u8]) -> IResult<&[u8], &[u8]> {
99     escaped(digit, '\\', one_of("\"n\\"))(i)
100   }
101   assert_eq!(esc2(&b"12\\nnn34"[..]), Ok((&b"nn34"[..], &b"12\\n"[..])));
102 }
103 
104 #[cfg(feature = "alloc")]
105 #[test]
106 fn escaping_str() {
107   use crate::character::streaming::one_of;
108 
109   fn esc(i: &str) -> IResult<&str, &str> {
110     escaped(alpha, '\\', one_of("\"n\\"))(i)
111   }
112   assert_eq!(esc("abcd;"), Ok((";", "abcd")));
113   assert_eq!(esc("ab\\\"cd;"), Ok((";", "ab\\\"cd")));
114   assert_eq!(esc("\\\"abcd;"), Ok((";", "\\\"abcd")));
115   assert_eq!(esc("\\n;"), Ok((";", "\\n")));
116   assert_eq!(esc("ab\\\"12"), Ok(("12", "ab\\\"")));
117   assert_eq!(
118     esc("AB\\"),
119     Err(Err::Error(error_position!("AB\\", ErrorKind::Escaped)))
120   );
121   assert_eq!(
122     esc("AB\\A"),
123     Err(Err::Error(error_node_position!(
124       "AB\\A",
125       ErrorKind::Escaped,
126       error_position!("A", ErrorKind::OneOf)
127     )))
128   );
129 
130   fn esc2(i: &str) -> IResult<&str, &str> {
131     escaped(digit, '\\', one_of("\"n\\"))(i)
132   }
133   assert_eq!(esc2("12\\nnn34"), Ok(("nn34", "12\\n")));
134 
135   fn esc3(i: &str) -> IResult<&str, &str> {
136     escaped(alpha, '\u{241b}', one_of("\"n"))(i)
137   }
138   assert_eq!(esc3("ab␛ncd;"), Ok((";", "ab␛ncd")));
139 }
140 
141 #[cfg(feature = "alloc")]
to_s(i: Vec<u8>) -> String142 fn to_s(i: Vec<u8>) -> String {
143   String::from_utf8_lossy(&i).into_owned()
144 }
145 
146 #[cfg(feature = "alloc")]
147 #[test]
escape_transform()148 fn escape_transform() {
149   fn esc(i: &[u8]) -> IResult<&[u8], String> {
150     map(
151       escaped_transform(
152         alpha,
153         '\\',
154         alt((
155           value(&b"\\"[..], tag("\\")),
156           value(&b"\""[..], tag("\"")),
157           value(&b"\n"[..], tag("n")),
158         )),
159       ),
160       to_s,
161     )(i)
162   }
163 
164   assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], String::from("abcd"))));
165   assert_eq!(
166     esc(&b"ab\\\"cd;"[..]),
167     Ok((&b";"[..], String::from("ab\"cd")))
168   );
169   assert_eq!(
170     esc(&b"\\\"abcd;"[..]),
171     Ok((&b";"[..], String::from("\"abcd")))
172   );
173   assert_eq!(esc(&b"\\n;"[..]), Ok((&b";"[..], String::from("\n"))));
174   assert_eq!(
175     esc(&b"ab\\\"12"[..]),
176     Ok((&b"12"[..], String::from("ab\"")))
177   );
178   assert_eq!(
179     esc(&b"AB\\"[..]),
180     Err(Err::Error(error_position!(
181       &b"\\"[..],
182       ErrorKind::EscapedTransform
183     )))
184   );
185   assert_eq!(
186     esc(&b"AB\\A"[..]),
187     Err(Err::Error(error_node_position!(
188       &b"AB\\A"[..],
189       ErrorKind::EscapedTransform,
190       error_position!(&b"A"[..], ErrorKind::Tag)
191     )))
192   );
193 
194   fn esc2(i: &[u8]) -> IResult<&[u8], String> {
195     map(
196       escaped_transform(
197         alpha,
198         '&',
199         alt((
200           value("è".as_bytes(), tag("egrave;")),
201           value("à".as_bytes(), tag("agrave;")),
202         )),
203       ),
204       to_s,
205     )(i)
206   }
207   assert_eq!(
208     esc2(&b"ab&egrave;DEF;"[..]),
209     Ok((&b";"[..], String::from("abèDEF")))
210   );
211   assert_eq!(
212     esc2(&b"ab&egrave;D&agrave;EF;"[..]),
213     Ok((&b";"[..], String::from("abèDàEF")))
214   );
215 }
216 
217 #[cfg(feature = "std")]
218 #[test]
219 fn escape_transform_str() {
220   fn esc(i: &str) -> IResult<&str, String> {
221     escaped_transform(
222       alpha,
223       '\\',
224       alt((
225         value("\\", tag("\\")),
226         value("\"", tag("\"")),
227         value("\n", tag("n")),
228       )),
229     )(i)
230   }
231 
232   assert_eq!(esc("abcd;"), Ok((";", String::from("abcd"))));
233   assert_eq!(esc("ab\\\"cd;"), Ok((";", String::from("ab\"cd"))));
234   assert_eq!(esc("\\\"abcd;"), Ok((";", String::from("\"abcd"))));
235   assert_eq!(esc("\\n;"), Ok((";", String::from("\n"))));
236   assert_eq!(esc("ab\\\"12"), Ok(("12", String::from("ab\""))));
237   assert_eq!(
238     esc("AB\\"),
239     Err(Err::Error(error_position!(
240       "\\",
241       ErrorKind::EscapedTransform
242     )))
243   );
244   assert_eq!(
245     esc("AB\\A"),
246     Err(Err::Error(error_node_position!(
247       "AB\\A",
248       ErrorKind::EscapedTransform,
249       error_position!("A", ErrorKind::Tag)
250     )))
251   );
252 
253   fn esc2(i: &str) -> IResult<&str, String> {
254     escaped_transform(
255       alpha,
256       '&',
257       alt((value("è", tag("egrave;")), value("à", tag("agrave;")))),
258     )(i)
259   }
260   assert_eq!(esc2("ab&egrave;DEF;"), Ok((";", String::from("abèDEF"))));
261   assert_eq!(
262     esc2("ab&egrave;D&agrave;EF;"),
263     Ok((";", String::from("abèDàEF")))
264   );
265 
266   fn esc3(i: &str) -> IResult<&str, String> {
267     escaped_transform(
268       alpha,
269       '␛',
270       alt((value("\0", tag("0")), value("\n", tag("n")))),
271     )(i)
272   }
273   assert_eq!(esc3("a␛0bc␛n"), Ok(("", String::from("a\0bc\n"))));
274 }
275 
276 #[test]
277 fn take_until_incomplete() {
278   use crate::bytes::streaming::take_until;
279   fn y(i: &[u8]) -> IResult<&[u8], &[u8]> {
280     take_until("end")(i)
281   }
282   assert_eq!(y(&b"nd"[..]), Err(Err::Incomplete(Needed::Unknown)));
283   assert_eq!(y(&b"123"[..]), Err(Err::Incomplete(Needed::Unknown)));
284   assert_eq!(y(&b"123en"[..]), Err(Err::Incomplete(Needed::Unknown)));
285 }
286 
287 #[test]
288 fn take_until_incomplete_s() {
289   use crate::bytes::streaming::take_until;
290   fn ys(i: &str) -> IResult<&str, &str> {
291     take_until("end")(i)
292   }
293   assert_eq!(ys("123en"), Err(Err::Incomplete(Needed::Unknown)));
294 }
295 
296 #[test]
297 fn recognize() {
298   use crate::bytes::streaming::{tag, take};
299   use crate::combinator::recognize;
300   use crate::sequence::delimited;
301 
302   fn x(i: &[u8]) -> IResult<&[u8], &[u8]> {
303     recognize(delimited(tag("<!--"), take(5_usize), tag("-->")))(i)
304   }
305   let r = x(&b"<!-- abc --> aaa"[..]);
306   assert_eq!(r, Ok((&b" aaa"[..], &b"<!-- abc -->"[..])));
307 
308   let semicolon = &b";"[..];
309 
310   fn ya(i: &[u8]) -> IResult<&[u8], &[u8]> {
311     recognize(alpha)(i)
312   }
313   let ra = ya(&b"abc;"[..]);
314   assert_eq!(ra, Ok((semicolon, &b"abc"[..])));
315 
316   fn yd(i: &[u8]) -> IResult<&[u8], &[u8]> {
317     recognize(digit)(i)
318   }
319   let rd = yd(&b"123;"[..]);
320   assert_eq!(rd, Ok((semicolon, &b"123"[..])));
321 
322   fn yhd(i: &[u8]) -> IResult<&[u8], &[u8]> {
323     recognize(hex_digit)(i)
324   }
325   let rhd = yhd(&b"123abcDEF;"[..]);
326   assert_eq!(rhd, Ok((semicolon, &b"123abcDEF"[..])));
327 
328   fn yod(i: &[u8]) -> IResult<&[u8], &[u8]> {
329     recognize(oct_digit)(i)
330   }
331   let rod = yod(&b"1234567;"[..]);
332   assert_eq!(rod, Ok((semicolon, &b"1234567"[..])));
333 
334   fn yan(i: &[u8]) -> IResult<&[u8], &[u8]> {
335     recognize(alphanumeric)(i)
336   }
337   let ran = yan(&b"123abc;"[..]);
338   assert_eq!(ran, Ok((semicolon, &b"123abc"[..])));
339 
340   fn ys(i: &[u8]) -> IResult<&[u8], &[u8]> {
341     recognize(space)(i)
342   }
343   let rs = ys(&b" \t;"[..]);
344   assert_eq!(rs, Ok((semicolon, &b" \t"[..])));
345 
346   fn yms(i: &[u8]) -> IResult<&[u8], &[u8]> {
347     recognize(multispace)(i)
348   }
349   let rms = yms(&b" \t\r\n;"[..]);
350   assert_eq!(rms, Ok((semicolon, &b" \t\r\n"[..])));
351 }
352 
353 #[test]
354 fn take_while() {
355   use crate::bytes::streaming::take_while;
356 
357   fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
358     take_while(is_alphabetic)(i)
359   }
360   let a = b"";
361   let b = b"abcd";
362   let c = b"abcd123";
363   let d = b"123";
364 
365   assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
366   assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::new(1))));
367   assert_eq!(f(&c[..]), Ok((&d[..], &b[..])));
368   assert_eq!(f(&d[..]), Ok((&d[..], &a[..])));
369 }
370 
371 #[test]
372 fn take_while1() {
373   use crate::bytes::streaming::take_while1;
374 
375   fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
376     take_while1(is_alphabetic)(i)
377   }
378   let a = b"";
379   let b = b"abcd";
380   let c = b"abcd123";
381   let d = b"123";
382 
383   assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
384   assert_eq!(f(&b[..]), Err(Err::Incomplete(Needed::new(1))));
385   assert_eq!(f(&c[..]), Ok((&b"123"[..], &b[..])));
386   assert_eq!(
387     f(&d[..]),
388     Err(Err::Error(error_position!(&d[..], ErrorKind::TakeWhile1)))
389   );
390 }
391 
392 #[test]
393 fn take_while_m_n() {
394   use crate::bytes::streaming::take_while_m_n;
395 
396   fn x(i: &[u8]) -> IResult<&[u8], &[u8]> {
397     take_while_m_n(2, 4, is_alphabetic)(i)
398   }
399   let a = b"";
400   let b = b"a";
401   let c = b"abc";
402   let d = b"abc123";
403   let e = b"abcde";
404   let f = b"123";
405 
406   assert_eq!(x(&a[..]), Err(Err::Incomplete(Needed::new(2))));
407   assert_eq!(x(&b[..]), Err(Err::Incomplete(Needed::new(1))));
408   assert_eq!(x(&c[..]), Err(Err::Incomplete(Needed::new(1))));
409   assert_eq!(x(&d[..]), Ok((&b"123"[..], &c[..])));
410   assert_eq!(x(&e[..]), Ok((&b"e"[..], &b"abcd"[..])));
411   assert_eq!(
412     x(&f[..]),
413     Err(Err::Error(error_position!(&f[..], ErrorKind::TakeWhileMN)))
414   );
415 }
416 
417 #[test]
418 fn take_till() {
419   use crate::bytes::streaming::take_till;
420 
421   fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
422     take_till(is_alphabetic)(i)
423   }
424   let a = b"";
425   let b = b"abcd";
426   let c = b"123abcd";
427   let d = b"123";
428 
429   assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
430   assert_eq!(f(&b[..]), Ok((&b"abcd"[..], &b""[..])));
431   assert_eq!(f(&c[..]), Ok((&b"abcd"[..], &b"123"[..])));
432   assert_eq!(f(&d[..]), Err(Err::Incomplete(Needed::new(1))));
433 }
434 
435 #[test]
436 fn take_till1() {
437   use crate::bytes::streaming::take_till1;
438 
439   fn f(i: &[u8]) -> IResult<&[u8], &[u8]> {
440     take_till1(is_alphabetic)(i)
441   }
442   let a = b"";
443   let b = b"abcd";
444   let c = b"123abcd";
445   let d = b"123";
446 
447   assert_eq!(f(&a[..]), Err(Err::Incomplete(Needed::new(1))));
448   assert_eq!(
449     f(&b[..]),
450     Err(Err::Error(error_position!(&b[..], ErrorKind::TakeTill1)))
451   );
452   assert_eq!(f(&c[..]), Ok((&b"abcd"[..], &b"123"[..])));
453   assert_eq!(f(&d[..]), Err(Err::Incomplete(Needed::new(1))));
454 }
455 
456 #[test]
457 fn take_while_utf8() {
458   use crate::bytes::streaming::take_while;
459 
460   fn f(i: &str) -> IResult<&str, &str> {
461     take_while(|c| c != '點')(i)
462   }
463 
464   assert_eq!(f(""), Err(Err::Incomplete(Needed::new(1))));
465   assert_eq!(f("abcd"), Err(Err::Incomplete(Needed::new(1))));
466   assert_eq!(f("abcd點"), Ok(("點", "abcd")));
467   assert_eq!(f("abcd點a"), Ok(("點a", "abcd")));
468 
469   fn g(i: &str) -> IResult<&str, &str> {
470     take_while(|c| c == '點')(i)
471   }
472 
473   assert_eq!(g(""), Err(Err::Incomplete(Needed::new(1))));
474   assert_eq!(g("點abcd"), Ok(("abcd", "點")));
475   assert_eq!(g("點點點a"), Ok(("a", "點點點")));
476 }
477 
478 #[test]
479 fn take_till_utf8() {
480   use crate::bytes::streaming::take_till;
481 
482   fn f(i: &str) -> IResult<&str, &str> {
483     take_till(|c| c == '點')(i)
484   }
485 
486   assert_eq!(f(""), Err(Err::Incomplete(Needed::new(1))));
487   assert_eq!(f("abcd"), Err(Err::Incomplete(Needed::new(1))));
488   assert_eq!(f("abcd點"), Ok(("點", "abcd")));
489   assert_eq!(f("abcd點a"), Ok(("點a", "abcd")));
490 
491   fn g(i: &str) -> IResult<&str, &str> {
492     take_till(|c| c != '點')(i)
493   }
494 
495   assert_eq!(g(""), Err(Err::Incomplete(Needed::new(1))));
496   assert_eq!(g("點abcd"), Ok(("abcd", "點")));
497   assert_eq!(g("點點點a"), Ok(("a", "點點點")));
498 }
499 
500 #[test]
501 fn take_utf8() {
502   use crate::bytes::streaming::{take, take_while};
503 
504   fn f(i: &str) -> IResult<&str, &str> {
505     take(3_usize)(i)
506   }
507 
508   assert_eq!(f(""), Err(Err::Incomplete(Needed::Unknown)));
509   assert_eq!(f("ab"), Err(Err::Incomplete(Needed::Unknown)));
510   assert_eq!(f("點"), Err(Err::Incomplete(Needed::Unknown)));
511   assert_eq!(f("ab點cd"), Ok(("cd", "ab點")));
512   assert_eq!(f("a點bcd"), Ok(("cd", "a點b")));
513   assert_eq!(f("a點b"), Ok(("", "a點b")));
514 
515   fn g(i: &str) -> IResult<&str, &str> {
516     take_while(|c| c == '點')(i)
517   }
518 
519   assert_eq!(g(""), Err(Err::Incomplete(Needed::new(1))));
520   assert_eq!(g("點abcd"), Ok(("abcd", "點")));
521   assert_eq!(g("點點點a"), Ok(("a", "點點點")));
522 }
523 
524 #[test]
525 fn take_while_m_n_utf8() {
526   use crate::bytes::streaming::take_while_m_n;
527 
528   fn parser(i: &str) -> IResult<&str, &str> {
529     take_while_m_n(1, 1, |c| c == 'A' || c == '��')(i)
530   }
531   assert_eq!(parser("A!"), Ok(("!", "A")));
532   assert_eq!(parser("��!"), Ok(("!", "��")));
533 }
534 
535 #[test]
536 fn take_while_m_n_utf8_full_match() {
537   use crate::bytes::streaming::take_while_m_n;
538 
539   fn parser(i: &str) -> IResult<&str, &str> {
540     take_while_m_n(1, 1, |c: char| c.is_alphabetic())(i)
541   }
542   assert_eq!(parser("øn"), Ok(("n", "ø")));
543 }
544 
545 #[test]
546 #[cfg(feature = "std")]
547 fn recognize_take_while() {
548   use crate::bytes::streaming::take_while;
549   use crate::character::is_alphanumeric;
550   use crate::combinator::recognize;
551 
552   fn x(i: &[u8]) -> IResult<&[u8], &[u8]> {
553     take_while(is_alphanumeric)(i)
554   }
555   fn y(i: &[u8]) -> IResult<&[u8], &[u8]> {
556     recognize(x)(i)
557   }
558   assert_eq!(x(&b"ab."[..]), Ok((&b"."[..], &b"ab"[..])));
559   println!("X: {:?}", x(&b"ab"[..]));
560   assert_eq!(y(&b"ab."[..]), Ok((&b"."[..], &b"ab"[..])));
561 }
562 
563 #[test]
564 fn length_bytes() {
565   use crate::{bytes::streaming::tag, multi::length_data, number::streaming::le_u8};
566 
567   fn x(i: &[u8]) -> IResult<&[u8], &[u8]> {
568     length_data(le_u8)(i)
569   }
570   assert_eq!(x(b"\x02..>>"), Ok((&b">>"[..], &b".."[..])));
571   assert_eq!(x(b"\x02.."), Ok((&[][..], &b".."[..])));
572   assert_eq!(x(b"\x02."), Err(Err::Incomplete(Needed::new(1))));
573   assert_eq!(x(b"\x02"), Err(Err::Incomplete(Needed::new(2))));
574 
575   fn y(i: &[u8]) -> IResult<&[u8], &[u8]> {
576     let (i, _) = tag("magic")(i)?;
577     length_data(le_u8)(i)
578   }
579   assert_eq!(y(b"magic\x02..>>"), Ok((&b">>"[..], &b".."[..])));
580   assert_eq!(y(b"magic\x02.."), Ok((&[][..], &b".."[..])));
581   assert_eq!(y(b"magic\x02."), Err(Err::Incomplete(Needed::new(1))));
582   assert_eq!(y(b"magic\x02"), Err(Err::Incomplete(Needed::new(2))));
583 }
584 
585 #[cfg(feature = "alloc")]
586 #[test]
587 fn case_insensitive() {
588   use crate::bytes::streaming::tag_no_case;
589 
590   fn test(i: &[u8]) -> IResult<&[u8], &[u8]> {
591     tag_no_case("ABcd")(i)
592   }
593   assert_eq!(test(&b"aBCdefgh"[..]), Ok((&b"efgh"[..], &b"aBCd"[..])));
594   assert_eq!(test(&b"abcdefgh"[..]), Ok((&b"efgh"[..], &b"abcd"[..])));
595   assert_eq!(test(&b"ABCDefgh"[..]), Ok((&b"efgh"[..], &b"ABCD"[..])));
596   assert_eq!(test(&b"ab"[..]), Err(Err::Incomplete(Needed::new(2))));
597   assert_eq!(
598     test(&b"Hello"[..]),
599     Err(Err::Error(error_position!(&b"Hello"[..], ErrorKind::Tag)))
600   );
601   assert_eq!(
602     test(&b"Hel"[..]),
603     Err(Err::Error(error_position!(&b"Hel"[..], ErrorKind::Tag)))
604   );
605 
606   fn test2(i: &str) -> IResult<&str, &str> {
607     tag_no_case("ABcd")(i)
608   }
609   assert_eq!(test2("aBCdefgh"), Ok(("efgh", "aBCd")));
610   assert_eq!(test2("abcdefgh"), Ok(("efgh", "abcd")));
611   assert_eq!(test2("ABCDefgh"), Ok(("efgh", "ABCD")));
612   assert_eq!(test2("ab"), Err(Err::Incomplete(Needed::new(2))));
613   assert_eq!(
614     test2("Hello"),
615     Err(Err::Error(error_position!(&"Hello"[..], ErrorKind::Tag)))
616   );
617   assert_eq!(
618     test2("Hel"),
619     Err(Err::Error(error_position!(&"Hel"[..], ErrorKind::Tag)))
620   );
621 }
622 
623 #[test]
624 fn tag_fixed_size_array() {
625   use crate::bytes::streaming::tag;
626 
627   fn test(i: &[u8]) -> IResult<&[u8], &[u8]> {
628     tag([0x42])(i)
629   }
630   fn test2(i: &[u8]) -> IResult<&[u8], &[u8]> {
631     tag(&[0x42])(i)
632   }
633   let input = [0x42, 0x00];
634   assert_eq!(test(&input), Ok((&b"\x00"[..], &b"\x42"[..])));
635   assert_eq!(test2(&input), Ok((&b"\x00"[..], &b"\x42"[..])));
636 }
637