|
|
@ -32,13 +32,6 @@ pub enum Sexp { |
|
|
|
List(Vec<Sexp>), |
|
|
|
List(Vec<Sexp>), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn sexp_size() { |
|
|
|
|
|
|
|
// I just want to see when this changes, in the diff.
|
|
|
|
|
|
|
|
use std::mem; |
|
|
|
|
|
|
|
assert_eq!(mem::size_of::<Sexp>(), mem::size_of::<isize>()*5); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The representation of an s-expression parse error.
|
|
|
|
/// The representation of an s-expression parse error.
|
|
|
|
pub struct Error { |
|
|
|
pub struct Error { |
|
|
|
/// The error message.
|
|
|
|
/// The error message.
|
|
|
@ -79,11 +72,6 @@ impl fmt::Debug for Error { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn show_an_error() { |
|
|
|
|
|
|
|
assert_eq!(format!("{:?}", parse("(aaaa").unwrap_err()), "1:4: unexpected eof"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_line_and_column(s: &str, pos: usize) -> (usize, usize) { |
|
|
|
fn get_line_and_column(s: &str, pos: usize) -> (usize, usize) { |
|
|
|
let mut line: usize = 1; |
|
|
|
let mut line: usize = 1; |
|
|
|
let mut col: isize = -1; |
|
|
|
let mut col: isize = -1; |
|
|
@ -98,20 +86,6 @@ fn get_line_and_column(s: &str, pos: usize) -> (usize, usize) { |
|
|
|
(line, cmp::max(col, 0) as usize) |
|
|
|
(line, cmp::max(col, 0) as usize) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn line_and_col_test() { |
|
|
|
|
|
|
|
let s = "0123456789\n0123456789\n\n6"; |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 4), (1, 4)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 10), (2, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 11), (2, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 15), (2, 4)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 21), (3, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 22), (4, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 23), (4, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 500), (4, 0)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cold] |
|
|
|
#[cold] |
|
|
|
fn err_impl(message: &'static str, s: &str, pos: &usize) -> Err { |
|
|
|
fn err_impl(message: &'static str, s: &str, pos: &usize) -> Err { |
|
|
@ -375,6 +349,10 @@ impl fmt::Debug for Sexp { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
|
|
|
|
mod test { |
|
|
|
|
|
|
|
use super::*; |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_hello_world() { |
|
|
|
fn test_hello_world() { |
|
|
|
assert_eq!( |
|
|
|
assert_eq!( |
|
|
@ -415,3 +393,31 @@ fn test_space_in_atom() { |
|
|
|
assert_eq!("(\"hello world\")", sexp_as_string); |
|
|
|
assert_eq!("(\"hello world\")", sexp_as_string); |
|
|
|
assert_eq!(sexp, parse(&sexp_as_string).unwrap()); |
|
|
|
assert_eq!(sexp, parse(&sexp_as_string).unwrap()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn show_an_error() { |
|
|
|
|
|
|
|
assert_eq!(format!("{:?}", parse("(aaaa").unwrap_err()), "1:4: unexpected eof"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn line_and_col_test() { |
|
|
|
|
|
|
|
let s = "0123456789\n0123456789\n\n6"; |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 4), (1, 4)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 10), (2, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 11), (2, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 15), (2, 4)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 21), (3, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 22), (4, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 23), (4, 0)); |
|
|
|
|
|
|
|
assert_eq!(get_line_and_column(s, 500), (4, 0)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn sexp_size() { |
|
|
|
|
|
|
|
// I just want to see when this changes, in the diff.
|
|
|
|
|
|
|
|
use std::mem; |
|
|
|
|
|
|
|
assert_eq!(mem::size_of::<Sexp>(), mem::size_of::<isize>()*5); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|