Skip to content

Commit f0c7857

Browse files
chansukepetrochenkov
chansuke
authored andcommitted
Separate libfmt_macros module
1 parent c77d3ae commit f0c7857

File tree

2 files changed

+244
-245
lines changed

2 files changed

+244
-245
lines changed

src/libfmt_macros/lib.rs

+1-245
Original file line numberDiff line numberDiff line change
@@ -622,248 +622,4 @@ impl<'a> Parser<'a> {
622622
}
623623

624624
#[cfg(test)]
625-
mod tests {
626-
use super::*;
627-
628-
fn same(fmt: &'static str, p: &[Piece<'static>]) {
629-
let parser = Parser::new(fmt, None, vec![], false);
630-
assert!(parser.collect::<Vec<Piece<'static>>>() == p);
631-
}
632-
633-
fn fmtdflt() -> FormatSpec<'static> {
634-
return FormatSpec {
635-
fill: None,
636-
align: AlignUnknown,
637-
flags: 0,
638-
precision: CountImplied,
639-
width: CountImplied,
640-
ty: "",
641-
};
642-
}
643-
644-
fn musterr(s: &str) {
645-
let mut p = Parser::new(s, None, vec![], false);
646-
p.next();
647-
assert!(!p.errors.is_empty());
648-
}
649-
650-
#[test]
651-
fn simple() {
652-
same("asdf", &[String("asdf")]);
653-
same("a{{b", &[String("a"), String("{b")]);
654-
same("a}}b", &[String("a"), String("}b")]);
655-
same("a}}", &[String("a"), String("}")]);
656-
same("}}", &[String("}")]);
657-
same("\\}}", &[String("\\"), String("}")]);
658-
}
659-
660-
#[test]
661-
fn invalid01() {
662-
musterr("{")
663-
}
664-
#[test]
665-
fn invalid02() {
666-
musterr("}")
667-
}
668-
#[test]
669-
fn invalid04() {
670-
musterr("{3a}")
671-
}
672-
#[test]
673-
fn invalid05() {
674-
musterr("{:|}")
675-
}
676-
#[test]
677-
fn invalid06() {
678-
musterr("{:>>>}")
679-
}
680-
681-
#[test]
682-
fn format_nothing() {
683-
same("{}",
684-
&[NextArgument(Argument {
685-
position: ArgumentImplicitlyIs(0),
686-
format: fmtdflt(),
687-
})]);
688-
}
689-
#[test]
690-
fn format_position() {
691-
same("{3}",
692-
&[NextArgument(Argument {
693-
position: ArgumentIs(3),
694-
format: fmtdflt(),
695-
})]);
696-
}
697-
#[test]
698-
fn format_position_nothing_else() {
699-
same("{3:}",
700-
&[NextArgument(Argument {
701-
position: ArgumentIs(3),
702-
format: fmtdflt(),
703-
})]);
704-
}
705-
#[test]
706-
fn format_type() {
707-
same("{3:a}",
708-
&[NextArgument(Argument {
709-
position: ArgumentIs(3),
710-
format: FormatSpec {
711-
fill: None,
712-
align: AlignUnknown,
713-
flags: 0,
714-
precision: CountImplied,
715-
width: CountImplied,
716-
ty: "a",
717-
},
718-
})]);
719-
}
720-
#[test]
721-
fn format_align_fill() {
722-
same("{3:>}",
723-
&[NextArgument(Argument {
724-
position: ArgumentIs(3),
725-
format: FormatSpec {
726-
fill: None,
727-
align: AlignRight,
728-
flags: 0,
729-
precision: CountImplied,
730-
width: CountImplied,
731-
ty: "",
732-
},
733-
})]);
734-
same("{3:0<}",
735-
&[NextArgument(Argument {
736-
position: ArgumentIs(3),
737-
format: FormatSpec {
738-
fill: Some('0'),
739-
align: AlignLeft,
740-
flags: 0,
741-
precision: CountImplied,
742-
width: CountImplied,
743-
ty: "",
744-
},
745-
})]);
746-
same("{3:*<abcd}",
747-
&[NextArgument(Argument {
748-
position: ArgumentIs(3),
749-
format: FormatSpec {
750-
fill: Some('*'),
751-
align: AlignLeft,
752-
flags: 0,
753-
precision: CountImplied,
754-
width: CountImplied,
755-
ty: "abcd",
756-
},
757-
})]);
758-
}
759-
#[test]
760-
fn format_counts() {
761-
use syntax_pos::{GLOBALS, Globals, edition};
762-
GLOBALS.set(&Globals::new(edition::DEFAULT_EDITION), || {
763-
same("{:10s}",
764-
&[NextArgument(Argument {
765-
position: ArgumentImplicitlyIs(0),
766-
format: FormatSpec {
767-
fill: None,
768-
align: AlignUnknown,
769-
flags: 0,
770-
precision: CountImplied,
771-
width: CountIs(10),
772-
ty: "s",
773-
},
774-
})]);
775-
same("{:10$.10s}",
776-
&[NextArgument(Argument {
777-
position: ArgumentImplicitlyIs(0),
778-
format: FormatSpec {
779-
fill: None,
780-
align: AlignUnknown,
781-
flags: 0,
782-
precision: CountIs(10),
783-
width: CountIsParam(10),
784-
ty: "s",
785-
},
786-
})]);
787-
same("{:.*s}",
788-
&[NextArgument(Argument {
789-
position: ArgumentImplicitlyIs(1),
790-
format: FormatSpec {
791-
fill: None,
792-
align: AlignUnknown,
793-
flags: 0,
794-
precision: CountIsParam(0),
795-
width: CountImplied,
796-
ty: "s",
797-
},
798-
})]);
799-
same("{:.10$s}",
800-
&[NextArgument(Argument {
801-
position: ArgumentImplicitlyIs(0),
802-
format: FormatSpec {
803-
fill: None,
804-
align: AlignUnknown,
805-
flags: 0,
806-
precision: CountIsParam(10),
807-
width: CountImplied,
808-
ty: "s",
809-
},
810-
})]);
811-
same("{:a$.b$s}",
812-
&[NextArgument(Argument {
813-
position: ArgumentImplicitlyIs(0),
814-
format: FormatSpec {
815-
fill: None,
816-
align: AlignUnknown,
817-
flags: 0,
818-
precision: CountIsName(Symbol::intern("b")),
819-
width: CountIsName(Symbol::intern("a")),
820-
ty: "s",
821-
},
822-
})]);
823-
});
824-
}
825-
#[test]
826-
fn format_flags() {
827-
same("{:-}",
828-
&[NextArgument(Argument {
829-
position: ArgumentImplicitlyIs(0),
830-
format: FormatSpec {
831-
fill: None,
832-
align: AlignUnknown,
833-
flags: (1 << FlagSignMinus as u32),
834-
precision: CountImplied,
835-
width: CountImplied,
836-
ty: "",
837-
},
838-
})]);
839-
same("{:+#}",
840-
&[NextArgument(Argument {
841-
position: ArgumentImplicitlyIs(0),
842-
format: FormatSpec {
843-
fill: None,
844-
align: AlignUnknown,
845-
flags: (1 << FlagSignPlus as u32) | (1 << FlagAlternate as u32),
846-
precision: CountImplied,
847-
width: CountImplied,
848-
ty: "",
849-
},
850-
})]);
851-
}
852-
#[test]
853-
fn format_mixture() {
854-
same("abcd {3:a} efg",
855-
&[String("abcd "),
856-
NextArgument(Argument {
857-
position: ArgumentIs(3),
858-
format: FormatSpec {
859-
fill: None,
860-
align: AlignUnknown,
861-
flags: 0,
862-
precision: CountImplied,
863-
width: CountImplied,
864-
ty: "a",
865-
},
866-
}),
867-
String(" efg")]);
868-
}
869-
}
625+
mod tests;

0 commit comments

Comments
 (0)