MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_parse_field_name

Function test_parse_field_name

crates/common/src/format.rs:1690–1731  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1688
1689 #[test]
1690 fn test_parse_field_name() {
1691 let parse = |s: &str| FieldName::parse(s.as_ref());
1692 assert_eq!(
1693 parse(""),
1694 Ok(FieldName {
1695 field_type: FieldType::Auto,
1696 parts: Vec::new(),
1697 })
1698 );
1699 assert_eq!(
1700 parse("0"),
1701 Ok(FieldName {
1702 field_type: FieldType::Index(0),
1703 parts: Vec::new(),
1704 })
1705 );
1706 assert_eq!(
1707 parse("key"),
1708 Ok(FieldName {
1709 field_type: FieldType::Keyword("key".into()),
1710 parts: Vec::new(),
1711 })
1712 );
1713 assert_eq!(
1714 parse("key.attr[0][string]"),
1715 Ok(FieldName {
1716 field_type: FieldType::Keyword("key".into()),
1717 parts: vec![
1718 FieldNamePart::Attribute("attr".into()),
1719 FieldNamePart::Index(0),
1720 FieldNamePart::StringIndex("string".into())
1721 ],
1722 })
1723 );
1724 assert_eq!(parse("key.."), Err(FormatParseError::EmptyAttribute));
1725 assert_eq!(parse("key[]"), Err(FormatParseError::EmptyAttribute));
1726 assert_eq!(parse("key["), Err(FormatParseError::MissingRightBracket));
1727 assert_eq!(
1728 parse("key[0]after"),
1729 Err(FormatParseError::InvalidCharacterAfterRightBracket)
1730 );
1731 }
1732}

Callers

nothing calls this directly

Calls 2

parseFunction · 0.50
as_refMethod · 0.45

Tested by

no test coverage detected