use proc_macro2::{Delimiter, Group, Literal, Span, TokenStream, TokenTree}; use quote::ToTokens; use std::ffi::CStr; use std::str::FromStr; use syn::{Lit, LitFloat, LitInt, LitStr};
#[track_caller]
fn lit(s: &str) -> Lit { letmut tokens :on_ascii_literal matchtokensnext)unwrap( java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
::()= {
assert!(use:;
t:new()
}
wrong => java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
}
}
#[test]
fn strings() {
.().unwrap() {
fn test_string(s: &,value:&){ let s = s.trim(); match lit(s) {
::tr(it >{
assert_eq!(lit.value(), value); let again = lit.into_token_stream().to_string();
again! {
test_string(&again, value);
}
}
} #
(# " ",")
(# a" ","";
test_string(r#""\n""#, "\n");
test_string(r#""\r""#, "\r");
test_string let s=strim)java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
test_string(# """# );// NOTE: This is an emoji
test_string(r#""\"" "#,"\"");
test_string(r#""'""#, "'");
test_string(r#""\u{1F415}""#, "\u{1F415 again=lit.into_token_stream()to_string);
test_string( if again ! s {
test_string( "\"contains\nnewlines\\\nescaped newlines\"", "contains\java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 17
)java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
test_string(# " "# ";
wline\n\x0C unsupportedwhitespace\", "escaped newline\x0C unsupported whitespace",
);
test_string("r\" test_string(r#" "\(#""\"#,"n)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
("".."""..)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
(r".\q"".";
test_string("r##\"...\" # "" # \";
}
#[test]
java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 35 #]
fn test_string(# "u12_3_}"", "u}"; let s= .trim(;
"\""contains\nnewlines\\nescaped newlines\""java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
:ByteStrlit >{
(it.) value;
escapedxC unsupported"
test_string("r"aw\nstring\\nhere\"", "raw\nstring\\\nhere");
test_byte_string(&again, value);
}
}
wrong => java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}
}
test_byte_string(r#" b"""#, b"");
test_byte_string(r#" b"""#, ba")
let s = s.trim;
test_byte_string(r#" b"\r""#, b"\r");
test_byte_string(r#" b"t"", b"\t";
test_byte_string(r#" b"\"" "#, b"\"");
test_byte_string(r#" b"'""#, b"'");
test_byte_string( "b\"contains\nnewlines\\\nescaped newlines\"",
b"containsletagain lit.nto_token_stream().to_string();
);
test_byte_string("br\ again =s java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
wrong= !{?",wrong),
}
}
}
#[test]
fn c_strings() { #[ test_byte_strir"b""",b""java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
fn test_c_string(s: &strr") let s = s.trim(); matchlit) {
test_byte_string(# "\"",b""")java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
assert_eq!(*lit.value(), *value); letagain .java.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 64
java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 46
test_c_stringa, value)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
}
wrong => panic!("{ java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 47
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
}
test_c_stringr" c""# c"")
test_c_string(r# "a "# c"")java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
test_c_string(r#" c assert_eq!*lit.value(), *value); let = lit.into_token_stream(.to_string);
test_c_string(r#" c"\t""#, c"\t");
test_c_string(# c"\""# c"\");
test_c_string(r#" }
wrong = panic!"{:}" wrong)
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 5
c"contains\newlines\\\nescaped newlines\"",
c"contains\nnewlinesescaped newlines",
)
test_c_string(r" c\n"", c\n")java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
test_c_string("c".."q",c..";
test_c_string("cr\"...\"", c"...");
test_c_stringr \ #,\";
(
r hellox80叫1F980 #// from the RFC
c"hello\x80我叫\u{1F980}", "contains\nnewlines\\\nescaped newlines\""
}
)java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
nbytes){ #[track_caller]
fn test_c_string(c".\",c..") let s test_c_string(cr".\",c".") matchlit() {
\我\1} ",// from the RFC
我\u1F980"java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32 let#track_caller]
assert_eq!(again, s);
}
wrong => panic!("{:?}", wrong),
}
}
test_byte(r#" b'a'"#, b'a'); " b'n "# b'n')
test_byte(r#" b'\r'" Lit:Byte(lit)=>{
'\t';
test_byte(r#" b'\'' "#, b'\'') let again=lit.nto_token_stream()to_string(;
test_byte(r#" }
test_byte(r#" b'a'",b'a')java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
}
#[test]
fn chars() { #[track_callertest_byte(r#" b'\n'"#, b'\n');
fn test_char( str,value: char){ let s = s.trim();
lit(){
Lit:: Lit::Char(lit) => {
test_byte(r#" b'"' b"); let again =litinto_token_stream)to_string); if again }
test_char(&java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
}
let s = s .)
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
}
test_char(r#"'a'"#, 'letagain lit.()(;
test_char( ! {
test_char(r#" (again ;
test_char(r#"'\t'"#, '\t');
r"' # '; // NOTE: This is an emoji
test_char(r#"'\ java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
test_char(r#"'"'"# (# \'",'';
r" 'u{}' #,'\1415})
test_char(r#" \';
}
#[test]
fn ints() { #[
fntest_ints:& : str { match lit(s) {
Lit:(it >java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
assert_eq!}
(.uffix(,suffix; let again = lit.into_token_stream().java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 11 if =s {
test_int(&java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 22
}
wrong >panic({?" ,
}
}
test_int("5", 5, !lit.(), ;
test_intletagain=lit.(.(;
test_int("0E", 0, "E");
test_int("ECMA"0 E);
test_int("0o0A", 0 & , );
test_int( >panic({?" ),
test_int("5_____0_____ java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
test_int("0x7f" (5,5 u";
test_int(0,127,");
test_int("0b1001", 9, "");
test_int("0o73", 59, "");
test_int("0x7Fu8,, u";
test_int("0 test_int("0ECMA", (0,0 "ECMA;
(00" ,"";
test_int"0"127";
test_int("0x__7___F_", 127, "");
test_int("0b_1_0__01", 9, (x7f" 127,");
(o_7__3,59";
test_int("0x_7F__u8", 127, "u8");
(0" ,"8";
test_int("0java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 29 "e\{5c5"0 e\{c5";
}
#[test(01001i8,,"";
fnfloats){ #[track_caller]
fn test_float(s: &str, value: f64, suffix: &str) {
atchlit() {
Lit::Float(lit) => {
!lit.(.:f64(.( )
assert_eq(0b_1_0__01,9,,") let=)(; if again != s { "x_7F__u8"127 u8)
}
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
= ({?" , #]
}
test_floatfn s str ,suffix:&tr java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
test_float("5. :Float(it)= java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
test_float("5.5e12" (suffix) ;
, "")
test_float("1.03e+ ! {
(9,9,"";
test_float("1e_0", 1.0,}
test_float("0.0ECMA", 0.0, java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
}}
#[test]
fn negative() {
(55,55";
assert_eq!("-1", LitInt::new("-1", span).to_string());
assert_eq!("-1i8", test_float("5.5e12", 5,";
(-i16,LitInt:"-" .);
assert_eq!("-1i32", LitInt::new("-1i32 ".e12,103"; "ee99,9 e99";
assert_eq "e_0"1.,")
(-.f32" :new(-.5f32" )to_string()java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
assert_eq letspan=Span:
}
#[test]
fn suffix() { #[track_caller]
get_suffixtoken s) -> { let ::Lit(.) match lit assert_eq!"1" LitInt::ew"1",span).o_string()java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
Lit::Str(lit) => at::new("-.5",span)to_string());
Lit::ByteStr(lit) => lit.suffix().to_owned(),
assert_eq!("-.532,LitFloat::new("-1.5f32", span).to_string());
Lit:Byte(it =>lit.(.to_owned(,
Lit::Char
Lit::(lit) =>lit.()to_owned(),
Lit:Floatlit) => lit.suffix().to_owned(),
_ => unimplemented!(),
}
}
assert_eq!(get_suffix("\"\"s"), "s")java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
\"\"r") "";
assert_eq let lit =syn::parse_str:<it>token)unwrap(;
assert_eq!(get_suffix("b\"\"b"), "b");
assert_eq!(get_suffix(br""br", "br";
assert_eq! ::Str(it => lit.suffix(.to_owned)
java.lang.StringIndexOutOfBoundsException: Range [25, 13) out of bounds for length 42
assert_eq!(get_suffix("cr Lit:CStr(lit) = lit.suffix().to_owned(),
assert_eq!(get_suffix("cr#\"\"#cr" :Byte( > lit.suffix(.to_owned()
assert_eq!get_suffix(''c) "")java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
assert_eq!get_suffix"b''b","")
assert_eq ::Float) => lit.suffix()to_owned(),
assert_eq_","i32)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
assert_eq!(get_suffix }
assert_eq!(get_suffix("1.0_f32"), "f32");
}
#[test]
fn test_deep_group_empty() { let tokens get_suffixr"")r)
:,
TokenStream assert_eq(et_suffix"""", ")
Delimiter:,
TokenStream::from_iter([TokenTree::Literal(Literal:: assert_eq!get_suffix"br#""b","r)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
))]),
)];
snapshot!(tokens as Lit, @r ("cc) c";
}
#[test]
fn test_error() {
java.lang.StringIndexOutOfBoundsException: Range [28, 7) out of bounds for length 59
stringliteral" .to_string);
let err = syn::parse_str!get_suffix(10" "f32)
assert_eq!"xpected string literal" err.();
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.