// Generated tests - do not edit by hand // Use: run `python3 SLS_Tests/yaml_to_rust_tests.py SLS_Tests/cases.yaml tests/lexer_tests_generated.rs` use sls; // crate under test const INT64_MIN: i128 = i64::MIN as i128; const UINT64_MAX: i128 = u64::MAX as i128; #[test] fn test_empty_statement() { let src = ""; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert!(got.is_empty()); } #[test] fn test_integer_default_decimal_0() { let src = "0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_default_decimal_1() { let src = "-1"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -1); } #[test] fn test_integer_default_decimal_42() { let src = "42"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_default_decimal_leading_zeros() { let src = "00042"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_default_hex_0xff() { let src = "0xFF"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_default_hex_0xdeadbeef() { let src = "0xdeadbeef"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 3735928559); } #[test] fn test_integer_default_hex_max() { let src = "0x7FFFFFFFFFFFFFFF"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 9223372036854775807); } #[test] fn test_integer_default_binary_0b1010() { let src = "0b1010"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 10); } #[test] fn test_integer_default_binary_all_ones() { let src = "0b1111111111111111"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 65535); } #[test] fn test_integer_default_octal_0o755() { let src = "0o755"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 493); } #[test] fn test_integer_default_octal_max_three_digits() { let src = "0o777"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 511); } #[test] fn test_integer_default_decimal_max_i64() { let src = "9223372036854775807"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 9223372036854775807); } #[test] fn test_integer_default_decimal_min_i64() { let src = "-9223372036854775808"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), INT64_MIN); } #[test] fn test_integer_default_decimal_with_underscore() { let src = "1_000_000"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 1000000); } #[test] fn test_integer_default_underscore_end() { let src = "42_"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_default_underscore_double() { let src = "4__2"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_default_whitespace() { let src = " 42 "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_default_hex_zero() { let src = "0x0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_default_binary_zero() { let src = "0b0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_default_octal_zero() { let src = "0o0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_default_decimal_with_commas_invalid() { let src = "1,000,000"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_default_invalid_characters() { let src = "12a3"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_default_invalid_prefix() { let src = "0b2"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_i8_decimal_positive() { let src = "42:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_i8_zero() { let src = "0:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_i8_decimal_negative() { let src = "-100:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -100); } #[test] fn test_integer_i8_hex() { let src = "0x7F:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 127); } #[test] fn test_integer_i8_binary() { let src = "0b1111:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 15); } #[test] fn test_integer_i8_octal() { let src = "0o77:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 63); } #[test] fn test_integer_i8_max_value() { let src = "127:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 127); } #[test] fn test_integer_i8_min_value() { let src = "-128:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -128); } #[test] fn test_integer_i8_overflow() { let src = "128:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_i8_underflow() { let src = "-129:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_i16_decimal_positive() { let src = "42:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_i16_zero() { let src = "0:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_i16_decimal_negative() { let src = "-100:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -100); } #[test] fn test_integer_i16_hex() { let src = "0xFF:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_i16_binary() { let src = "0b1111:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 15); } #[test] fn test_integer_i16_octal() { let src = "0o77:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 63); } #[test] fn test_integer_i16_max_value() { let src = "32767:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 32767); } #[test] fn test_integer_i16_min_value() { let src = "-32768:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -32768); } #[test] fn test_integer_i16_overflow() { let src = "32768:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_i16_underflow() { let src = "-32769:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_i32_decimal_positive() { let src = "42:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_i32_zero() { let src = "0:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_i32_decimal_negative() { let src = "-100:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -100); } #[test] fn test_integer_i32_hex() { let src = "0xFF:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_i32_binary() { let src = "0b1111:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 15); } #[test] fn test_integer_i32_octal() { let src = "0o77:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 63); } #[test] fn test_integer_i32_max_value() { let src = "2147483647:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 2147483647); } #[test] fn test_integer_i32_min_value() { let src = "-2147483648:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -2147483648); } #[test] fn test_integer_i32_overflow() { let src = "2147483648:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_i32_underflow() { let src = "-2147483649:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_i32_with_underscores() { let src = "1_000_000:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 1000000); } #[test] fn test_integer_i64_decimal_positive() { let src = "42:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_i64_zero() { let src = "0:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_i64_decimal_negative() { let src = "-100:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -100); } #[test] fn test_integer_i64_hex() { let src = "0xFF:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_i64_binary() { let src = "0b1111:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 15); } #[test] fn test_integer_i64_octal() { let src = "0o77:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 63); } #[test] fn test_integer_i64_max_value() { let src = "9223372036854775807:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 9223372036854775807); } #[test] fn test_integer_i64_min_value() { let src = "-9223372036854775808:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), INT64_MIN); } #[test] fn test_integer_i64_overflow() { let src = "9223372036854775808:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_i64_underflow() { let src = "-9223372036854775809:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_i64_with_underscores() { let src = "1_000_000:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 1000000); } #[test] fn test_integer_u8_decimal_positive() { let src = "42:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_u8_zero() { let src = "0:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_u8_hex() { let src = "0xFF:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_u8_binary() { let src = "0b1111:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 15); } #[test] fn test_integer_u8_octal() { let src = "0o77:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 63); } #[test] fn test_integer_u8_max_value() { let src = "255:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_u8_min_value() { let src = "0:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_u8_overflow() { let src = "256:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_u8_underflow() { let src = "-1:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_u16_decimal_positive() { let src = "42:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_u16_zero() { let src = "0:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_u16_hex() { let src = "0xFF:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_u16_binary() { let src = "0b1111:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 15); } #[test] fn test_integer_u16_octal() { let src = "0o77:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 63); } #[test] fn test_integer_u16_max_value() { let src = "65535:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 65535); } #[test] fn test_integer_u16_min_value() { let src = "0:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_u16_overflow() { let src = "65536:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_u16_underflow() { let src = "-1:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_u32_decimal_positive() { let src = "42:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_u32_zero() { let src = "0:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_u32_hex() { let src = "0xFF:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_u32_binary() { let src = "0b1111:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 15); } #[test] fn test_integer_u32_octal() { let src = "0o77:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 63); } #[test] fn test_integer_u32_max_value() { let src = "4294967295:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 4294967295); } #[test] fn test_integer_u32_min_value() { let src = "0:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_u32_overflow() { let src = "4294967296:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_u32_underflow() { let src = "-1:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_u32_with_underscores() { let src = "1_000_000:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 1000000); } #[test] fn test_integer_u64_decimal_positive() { let src = "42:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_u64_zero() { let src = "0:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_u64_hex() { let src = "0xFF:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_u64_binary() { let src = "0b1111:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 15); } #[test] fn test_integer_u64_octal() { let src = "0o77:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 63); } #[test] fn test_integer_u64_max_value() { let src = "18446744073709551615:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), UINT64_MAX); } #[test] fn test_integer_u64_min_value() { let src = "0:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_integer_u64_overflow() { let src = "18446744073709551616:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_u64_underflow() { let src = "-1:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_integer_u64_with_underscores() { let src = "1_000_000:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 1000000); } #[test] fn test_integer_i8_hex_max() { let src = "0x7F:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 127); } #[test] fn test_integer_i8_binary_max() { let src = "0b01111111:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 127); } #[test] fn test_integer_i8_octal_max() { let src = "0o177:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 127); } #[test] fn test_integer_i8_negative_hex() { let src = "-0x80:i8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -128); } #[test] fn test_integer_u8_hex_max() { let src = "0xFF:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_u8_binary_max() { let src = "0b11111111:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_u8_octal_max() { let src = "0o377:u8"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_i16_hex_sample() { let src = "0x1234:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 4660); } #[test] fn test_integer_i16_binary_sample() { let src = "0b1111111100000000:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), -256); } #[test] fn test_integer_i16_octal_sample() { let src = "0o1234:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 668); } #[test] fn test_integer_u16_hex_max() { let src = "0xFFFF:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 65535); } #[test] fn test_integer_u16_binary_max() { let src = "0b1111111111111111:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 65535); } #[test] fn test_integer_u16_octal_max() { let src = "0o177777:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 65535); } #[test] fn test_integer_u16_decimal_mid() { let src = "50000:u16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 50000); } #[test] fn test_integer_i32_hex_sample() { let src = "0xABCD:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 43981); } #[test] fn test_integer_i32_binary_sample() { let src = "0b11110000:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 240); } #[test] fn test_integer_u32_hex_max() { let src = "0xFFFFFFFF:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 4294967295); } #[test] fn test_integer_u32_binary_sample() { let src = "0b11111111000000001111111100000000:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 4278255360); } #[test] fn test_integer_u32_octal_max() { let src = "0o37777777777:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 4294967295); } #[test] fn test_integer_u32_decimal_mid() { let src = "1000000:u32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 1000000); } #[test] fn test_integer_i64_decimal_positive_42() { let src = "42:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_i64_hex_0xff() { let src = "0xFF:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 255); } #[test] fn test_integer_i64_binary_0b1010() { let src = "0b1010:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 10); } #[test] fn test_integer_i64_octal_0o755() { let src = "0o755:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 493); } #[test] fn test_integer_u64_hex_max() { let src = "0xFFFFFFFFFFFFFFFF:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), UINT64_MAX); } #[test] fn test_integer_u64_binary_sample() { let src = "0b1010101010101010:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 43690); } #[test] fn test_integer_u64_octal_sample() { let src = "0o7777:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 4095); } #[test] fn test_integer_u64_decimal() { let src = "42:u64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_integer_hex_with_underscores() { let src = "0xDEAD_BEEF:i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 3735928559); } #[test] fn test_integer_binary_with_underscores() { let src = "0b1111_0000_1010_0101:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 61605); } #[test] fn test_integer_octal_with_underscores() { let src = "0o7_7_7:i16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 511); } #[test] fn test_float_default_simple() { let src = "3.14"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.14).abs() < 1e-12); } #[test] fn test_float_default_zero() { let src = "0.0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 0.0).abs() < 1e-12); } #[test] fn test_float_default_negative() { let src = "-2.5"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - -2.5).abs() < 1e-12); } #[test] fn test_float_default_one() { let src = "1.0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1.0).abs() < 1e-12); } #[test] fn test_float_f32_simple() { let src = "3.14:f32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.14).abs() < 1e-12); } #[test] fn test_float_f64_simple() { let src = "2.718:f64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 2.718).abs() < 1e-12); } #[test] fn test_float_default_leading_zeros() { let src = "00042.5"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 42.5).abs() < 1e-12); } #[test] fn test_float_default_leading_zero_decimal() { let src = "0.5"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 0.5).abs() < 1e-12); } #[test] fn test_float_default_trailing_zeros() { let src = "3.1400"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.14).abs() < 1e-12); } #[test] fn test_float_default_no_leading_digit() { let src = ".5"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 0.5).abs() < 1e-12); } #[test] fn test_float_default_no_leading_digit_negative() { let src = "-.25"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - -0.25).abs() < 1e-12); } #[test] fn test_float_default_no_trailing_digits() { let src = "42."; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 42.0).abs() < 1e-12); } #[test] fn test_float_default_no_trailing_digits_negative() { let src = "-7."; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - -7.0).abs() < 1e-12); } #[test] fn test_float_default_very_small() { let src = "0.000001"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1e-06).abs() < 1e-12); } #[test] fn test_float_default_very_large() { let src = "1000000.0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1000000.0).abs() < 1e-12); } #[test] fn test_float_default_underscore_integer_part() { let src = "1_000_000.5"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1000000.5).abs() < 1e-12); } #[test] fn test_float_default_underscore_decimal_part() { let src = "3.141_592_653"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.141592653).abs() < 1e-12); } #[test] fn test_float_default_underscore_both_parts() { let src = "1_234.567_89"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1234.56789).abs() < 1e-12); } #[test] fn test_float_default_underscore_trailing() { let src = "42.5_"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 42.5).abs() < 1e-12); } #[test] fn test_float_default_underscore_double() { let src = "4__2.5"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 42.5).abs() < 1e-12); } #[test] fn test_float_f32_with_underscores() { let src = "1_234.567_89:f32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1234.56789).abs() < 1e-12); } #[test] fn test_float_f32_precision_limit() { let src = "1.2345678:f32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1.2345678).abs() < 1e-12); } #[test] fn test_float_f32_high_precision() { let src = "3.141592653589793:f32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.141592653589793).abs() < 1e-12); } #[test] fn test_float_f64_precision_limit() { let src = "1.234567890123456:f64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1.234567890123456).abs() < 1e-12); } #[test] fn test_float_f64_high_precision() { let src = "3.141592653589793238:f64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.141592653589793).abs() < 1e-12); } #[test] fn test_float_f64_close_numbers_1() { let src = "1.0000000000000001:f64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1.0).abs() < 1e-12); } #[test] fn test_float_f64_close_numbers_2() { let src = "1.0000000000000002:f64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1.0000000000000002).abs() < 1e-12); } #[test] fn test_float_invalid_multiple_decimal_points() { let src = "3.14.159"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_float_invalid_characters() { let src = "3.1a4"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_float_invalid_type_annotation() { let src = "3.14:i32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_float_invalid_type_name() { let src = "3.14:f16"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_float_invalid_comma_separator() { let src = "1,234.56"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_float_default_leading_whitespace() { let src = " 3.14"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.14).abs() < 1e-12); } #[test] fn test_float_default_trailing_whitespace() { let src = "3.14 "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.14).abs() < 1e-12); } #[test] fn test_float_default_both_whitespace() { let src = " 3.14 "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.14).abs() < 1e-12); } #[test] fn test_float_f32_with_whitespace() { let src = " 2.718:f32 "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 2.718).abs() < 1e-12); } #[test] fn test_float_default_pi_approximate() { let src = "3.141592653589793"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.141592653589793).abs() < 1e-12); } #[test] fn test_float_f32_pi_approximate() { let src = "3.1415927:f32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 3.1415927).abs() < 1e-12); } #[test] fn test_float_default_euler_approximate() { let src = "2.718281828459045"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 2.718281828459045).abs() < 1e-12); } #[test] fn test_float_f32_euler_approximate() { let src = "2.7182817:f32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 2.7182817).abs() < 1e-12); } #[test] fn test_float_default_golden_ratio() { let src = "1.618033988749895"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1.618033988749895).abs() < 1e-12); } #[test] fn test_float_default_sqrt2() { let src = "1.4142135623730951"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 1.4142135623730951).abs() < 1e-12); } #[test] fn test_float_default_positive_zero() { let src = "0.0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 0.0).abs() < 1e-12); } #[test] fn test_float_default_negative_zero() { let src = "-0.0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - -0.0).abs() < 1e-12); } #[test] fn test_float_f32_positive_zero() { let src = "0.0:f32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - 0.0).abs() < 1e-12); } #[test] fn test_float_f32_negative_zero() { let src = "-0.0:f32"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Float); assert!(got[0].float.is_some(), "expected float value"); assert!((got[0].float.unwrap() - -0.0).abs() < 1e-12); } #[test] fn test_char_simple_letter_uppercase_a() { let src = "'A'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 65); } #[test] fn test_char_simple_letter_lowercase_a() { let src = "'a'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 97); } #[test] fn test_char_simple_letter_uppercase_z() { let src = "'Z'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 90); } #[test] fn test_char_simple_letter_lowercase_z() { let src = "'z'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 122); } #[test] fn test_char_digit_0() { let src = "'0'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 48); } #[test] fn test_char_digit_5() { let src = "'5'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 53); } #[test] fn test_char_digit_9() { let src = "'9'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 57); } #[test] fn test_char_space() { let src = "' '"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 32); } #[test] fn test_char_exclamation() { let src = "'!'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 33); } #[test] fn test_char_question_mark() { let src = "'?'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 63); } #[test] fn test_char_period() { let src = "'.'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 46); } #[test] fn test_char_comma() { let src = "','"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 44); } #[test] fn test_char_semicolon() { let src = "';'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 59); } #[test] fn test_char_colon() { let src = "':'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 58); } #[test] fn test_char_plus() { let src = "'+'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 43); } #[test] fn test_char_minus() { let src = "'-'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 45); } #[test] fn test_char_asterisk() { let src = "'*'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 42); } #[test] fn test_char_slash() { let src = "'/'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 47); } #[test] fn test_char_equals() { let src = "'='"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 61); } #[test] fn test_char_less_than() { let src = "'<'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 60); } #[test] fn test_char_greater_than() { let src = "'>'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 62); } #[test] fn test_char_left_paren() { let src = "'('"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 40); } #[test] fn test_char_right_paren() { let src = "')'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 41); } #[test] fn test_char_left_bracket() { let src = "'['"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 91); } #[test] fn test_char_right_bracket() { let src = "']'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 93); } #[test] fn test_char_left_brace() { let src = "'{'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 123); } #[test] fn test_char_right_brace() { let src = "'}'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 125); } #[test] fn test_char_escape_single_quote() { let src = "'\\\\''"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 39); } #[test] fn test_char_escape_newline() { let src = "'\\\\n'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 10); } #[test] fn test_char_escape_null_character() { let src = "'\\\\0'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_char_escape_backslash() { let src = "'\\\\\\\\'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 92); } #[test] fn test_char_escape_tab() { let src = "'\\\\t'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 9); } #[test] fn test_char_escape_carriage_return() { let src = "'\\\\r'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 13); } #[test] fn test_char_with_leading_whitespace() { let src = " 'A'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 65); } #[test] fn test_char_with_trailing_whitespace() { let src = "'A' "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 65); } #[test] fn test_char_with_both_whitespace() { let src = " 'A' "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 65); } #[test] fn test_char_tab_before() { let src = "\\t'B'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 66); } #[test] fn test_char_newline_before() { let src = "\\n'C'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric char code"); assert_eq!(got[0].numeric.unwrap(), 67); } #[test] fn test_char_empty_literal() { let src = "''"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_char_multiple_characters() { let src = "'AB'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_char_unclosed_quote() { let src = "'A"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_char_unescaped_newline() { let src = "'\\n'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_char_invalid_escape() { let src = "'\\\\q'"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_identifier_simple_lowercase() { let src = "hello"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello"); } #[test] fn test_identifier_simple_uppercase() { let src = "HELLO"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "HELLO"); } #[test] fn test_identifier_mixed_case() { let src = "HelloWorld"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "HelloWorld"); } #[test] fn test_identifier_single_letter() { let src = "x"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "x"); } #[test] fn test_identifier_single_letter_upper() { let src = "X"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "X"); } #[test] fn test_identifier_with_numbers() { let src = "var123"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "var123"); } #[test] fn test_identifier_numbers_end() { let src = "myVar2"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "myVar2"); } #[test] fn test_identifier_mixed_numbers() { let src = "a1b2c3"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "a1b2c3"); } #[test] fn test_identifier_with_underscore() { let src = "hello_world"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello_world"); } #[test] fn test_identifier_leading_underscore() { let src = "_private"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "_private"); } #[test] fn test_identifier_multiple_underscores() { let src = "my_long_var_name"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "my_long_var_name"); } #[test] fn test_identifier_double_underscore() { let src = "my__var"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "my__var"); } #[test] fn test_identifier_trailing_underscore() { let src = "var_"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "var_"); } #[test] fn test_identifier_only_underscores() { let src = "___"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "___"); } #[test] fn test_identifier_snake_case() { let src = "my_variable_name"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "my_variable_name"); } #[test] fn test_identifier_camel_case() { let src = "myVariableName"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "myVariableName"); } #[test] fn test_identifier_pascal_case() { let src = "MyClassName"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "MyClassName"); } #[test] fn test_identifier_all_caps() { let src = "MY_CONSTANT"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "MY_CONSTANT"); } #[test] fn test_identifier_with_dash() { let src = "my-var"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "my-var"); } #[test] fn test_identifier_literal_simple() { let src = "::hello"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello"); } #[test] fn test_identifier_literal_uppercase() { let src = "::Point"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "Point"); } #[test] fn test_identifier_literal_snake_case() { let src = "::my_var"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "my_var"); } #[test] fn test_identifier_literal_type_i64() { let src = "::i64"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "i64"); } #[test] fn test_identifier_literal_type_string() { let src = "::String"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "String"); } #[test] fn test_identifier_literal_type_point() { let src = "::Point"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "Point"); } #[test] fn test_identifier_literal_trait_addable() { let src = "::Addable"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "Addable"); } #[test] fn test_identifier_literal_trait_drawable() { let src = "::Drawable"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "Drawable"); } #[test] fn test_identifier_literal_field_x() { let src = "::x"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "x"); } #[test] fn test_identifier_literal_field_width() { let src = "::width"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "width"); } #[test] fn test_identifier_literal_with_underscore() { let src = "::_private"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "_private"); } #[test] fn test_identifier_literal_multiple_underscores() { let src = "::my_long_name"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "my_long_name"); } #[test] fn test_identifier_literal_with_numbers() { let src = "::var123"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "var123"); } #[test] fn test_identifier_leading_whitespace() { let src = " hello"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello"); } #[test] fn test_identifier_trailing_whitespace() { let src = "hello "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello"); } #[test] fn test_identifier_both_whitespace() { let src = " hello "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello"); } #[test] fn test_identifier_tab_before() { let src = "\\thello"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello"); } #[test] fn test_identifier_literal_leading_whitespace() { let src = " ::hello"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello"); } #[test] fn test_identifier_literal_trailing_whitespace() { let src = "::hello "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello"); } #[test] fn test_identifier_literal_both_whitespace() { let src = " ::hello "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "hello"); } #[test] fn test_identifier_moderate_length() { let src = "thisIsAReasonablyLongVariableName"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "thisIsAReasonablyLongVariableName"); } #[test] fn test_identifier_very_long() { let src = "this_is_a_very_long_identifier_name_that_someone_might_use_for_some_reason"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "this_is_a_very_long_identifier_name_that_someone_might_use_for_some_reason"); } #[test] fn test_identifier_long_with_numbers() { let src = "variable_with_many_numbers_123_456_789_000"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "variable_with_many_numbers_123_456_789_000"); } #[test] fn test_identifier_starting_with_number() { let src = "123abc"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_identifier_with_octothorpe() { let src = "my#var"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "my"); } #[test] fn test_identifier_with_colon() { let src = "my:var"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_identifier_double_colon_inside() { let src = "my::var"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_identifier_only_numbers() { let src = "123"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 123); } #[test] fn test_identifier_literal_empty() { let src = "::"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_identifier_case_lower() { let src = "variable"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "variable"); } #[test] fn test_identifier_case_upper() { let src = "VARIABLE"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "VARIABLE"); } #[test] fn test_identifier_case_mixed() { let src = "Variable"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "Variable"); } #[test] fn test_identifier_case_camel() { let src = "variableName"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "variableName"); } #[test] fn test_identifier_case_pascal() { let src = "VariableName"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "VariableName"); } #[test] fn test_identifier_reserved_word_if() { let src = "if"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "if"); } #[test] fn test_identifier_reserved_word_while() { let src = "while"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "while"); } #[test] fn test_identifier_reserved_word_for() { let src = "for"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "for"); } #[test] fn test_identifier_reserved_word_match() { let src = "match"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "match"); } #[test] fn test_identifier_reserved_word_break() { let src = "break"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "break"); } #[test] fn test_identifier_reserved_word_continue() { let src = "continue"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "continue"); } #[test] fn test_identifier_reserved_word_fn() { let src = "fn"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "fn"); } #[test] fn test_identifier_reserved_word_struct() { let src = "struct"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "struct"); } #[test] fn test_identifier_reserved_word_union() { let src = "union"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "union"); } #[test] fn test_identifier_reserved_word_enum() { let src = "enum"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "enum"); } #[test] fn test_identifier_reserved_word_trait() { let src = "trait"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "trait"); } #[test] fn test_identifier_reserved_word_impl() { let src = "impl"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "impl"); } #[test] fn test_identifier_reserved_word_inher() { let src = "inher"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "inher"); } #[test] fn test_identifier_reserved_word_dup() { let src = "dup"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "dup"); } #[test] fn test_identifier_reserved_word_drop() { let src = "drop"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "drop"); } #[test] fn test_identifier_reserved_word_swap() { let src = "swap"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "swap"); } #[test] fn test_identifier_reserved_word_over() { let src = "over"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "over"); } #[test] fn test_identifier_reserved_word_rot() { let src = "rot"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "rot"); } #[test] fn test_identifier_reserved_word_pick() { let src = "pick"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "pick"); } #[test] fn test_identifier_reserved_word_roll() { let src = "roll"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "roll"); } #[test] fn test_identifier_reserved_word_depth() { let src = "depth"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "depth"); } #[test] fn test_bool_true() { let src = "true"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "true"); } #[test] fn test_bool_false() { let src = "false"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "false"); } #[test] fn test_bool_true_leading_whitespace() { let src = " true"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "true"); } #[test] fn test_bool_true_trailing_whitespace() { let src = "true "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "true"); } #[test] fn test_bool_true_both_whitespace() { let src = " true "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "true"); } #[test] fn test_bool_true_tab_before() { let src = "\\ttrue"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "true"); } #[test] fn test_bool_false_leading_whitespace() { let src = " false"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "false"); } #[test] fn test_bool_false_trailing_whitespace() { let src = "false "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "false"); } #[test] fn test_bool_false_both_whitespace() { let src = " false "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "false"); } #[test] fn test_bool_false_tab_before() { let src = "\\tfalse"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "false"); } #[test] fn test_bool_true_capitalized() { let src = "True"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "True"); } #[test] fn test_bool_false_capitalized() { let src = "False"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "False"); } #[test] fn test_bool_true_all_caps() { let src = "TRUE"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "TRUE"); } #[test] fn test_bool_false_all_caps() { let src = "FALSE"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "FALSE"); } #[test] fn test_bool_true_mixed_case() { let src = "tRuE"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "tRuE"); } #[test] fn test_bool_false_mixed_case() { let src = "fAlSe"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "fAlSe"); } #[test] fn test_bool_numeric_1() { let src = "1"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 1); } #[test] fn test_bool_numeric_0() { let src = "0"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Int); assert!(got[0].numeric.is_some(), "expected numeric value"); assert_eq!(got[0].numeric.unwrap(), 0); } #[test] fn test_bool_yes() { let src = "yes"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "yes"); } #[test] fn test_bool_no() { let src = "no"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "no"); } #[test] fn test_bool_typo_ture() { let src = "ture"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "ture"); } #[test] fn test_bool_typo_flase() { let src = "flase"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "flase"); } #[test] fn test_bool_multiple_true_false() { let src = "true false"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 2usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "true"); assert_eq!(got[1].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[1].lexeme, "false"); } #[test] fn test_bool_multiple_same() { let src = "true true"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 2usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "true"); assert_eq!(got[1].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[1].lexeme, "true"); } #[test] fn test_bool_three_values() { let src = "true false true"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 3usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[0].lexeme, "true"); assert_eq!(got[1].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[1].lexeme, "false"); assert_eq!(got[2].ttype, sls::lexer::TokenType::Ident); assert_eq!(got[2].lexeme, "true"); } #[test] fn test_tokenstring_empty() { let src = "{ }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_single_integer() { let src = "{ 42 }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_single_identifier() { let src = "{ dup }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_two_integers() { let src = "{ 2 3 }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_simple_expression() { let src = "{ 2 3 + }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_stack_ops() { let src = "{ dup * }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_integer_literals() { let src = "{ 0 42 -10 1000 }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_float_literals() { let src = "{ 3.14 -2.5 0.0 }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_char_literal() { let src = "{ 'A' }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_boolean_literals() { let src = "{ true false }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_multiple_identifiers() { let src = "{ dup swap over }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_identifier_literals() { let src = "{ ::x ::y }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_mixed_identifiers() { let src = "{ ::Point get x swap }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_nested_single() { let src = "{ { 2 3 + } }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_nested_with_others() { let src = "{ x { dup * } }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_multiple_nested() { let src = "{ { 2 3 + } { 4 5 * } }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_double_nested() { let src = "{ { { 42 } } }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_complex_nesting() { let src = "{ 1 { 2 { 3 } 4 } 5 }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_no_whitespace() { let src = "{2 3 +}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_extra_whitespace() { let src = "{ 2 3 + }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_leading_whitespace_outside() { let src = " { 2 3 + }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_trailing_whitespace_outside() { let src = "{ 2 3 + } "; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_with_tabs() { let src = "{\\t2\\t3\\t+\\t}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_multiline_simple() { let src = "{\\n 2 3 +\\n}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_multiline_multiple() { let src = "{\\n dup\\n *\\n 2\\n +\\n}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_mixed_line_breaks() { let src = "{ 1 2\\n3 4\\n\\n5 6 }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_indented_multiline() { let src = "{\\n dup 0 >\\n { }\\n { 0 swap - }\\n if\\n}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_comment_end_of_line() { let src = "{ 2 3 + // add them\\n}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_multiple_comments() { let src = "{ 2 // first\\n3 // second\\n+ // add\\n}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_comment_own_line() { let src = "{\\n // This is a comment\\n 2 3 +\\n}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_comment_at_start() { let src = "{ // comment\\n2 3 + }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_multiple_comment_lines() { let src = "{\\n // First comment\\n // Second comment\\n 2 3 +\\n}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_comments_nested() { let src = "{ { 2 3 + // inner comment\\n} // outer comment\\n}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_unclosed() { let src = "{ 2 3 +"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_tokenstring_unclosed_nested() { let src = "{ { 2 3 + }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_tokenstring_extra_closing_brace() { let src = "{ 2 3 + } }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 2usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); assert_eq!(got[1].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_tokenstring_only_closing_brace() { let src = "}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); assert_eq!(got[0].ttype, sls::lexer::TokenType::Illegal); } #[test] fn test_tokenstring_error_inside() { let src = "{ 2 3a + }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_function_body() { let src = "{ dup * }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_loop_body() { let src = "{ dup print 1 + }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_struct_fields() { let src = "{ x: y: }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_lambda() { let src = "{ 2 * }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_array_map() { let src = "{ dup * }"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); } #[test] fn test_tokenstring_conditional_complex() { let src = "{\\n dup 0 >\\n { dup * }\\n { drop 0 }\\n if\\n}"; let mut lexer = sls::lexer::Lexer::new(src); let mut got = vec![]; loop { let t = lexer.next_token(); if t.ttype == sls::lexer::TokenType::Eof { break; } got.push(t); } assert_eq!(got.len(), 1usize, "token count mismatch"); // token_string check not implemented; received token: {:#?} // TODO: implement nested expectations // for now just assert we got an Ident or similar assert!(!got[0].lexeme.is_empty()); }