Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[glsl-in] consolidate tests #206

Merged
merged 2 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 11 additions & 80 deletions src/front/glsl/lex_tests.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,9 @@
use super::{lex::Lexer, parser::Token::*, token::TokenMetadata};

#[test]
fn glsl_lex_simple() {
let source = "void main() {\n}";
let mut lex = Lexer::new(source);

assert_eq!(
lex.next().unwrap(),
Void(TokenMetadata {
line: 0,
chars: 0..4
})
);
assert_eq!(
lex.next().unwrap(),
Identifier((
TokenMetadata {
line: 0,
chars: 5..9
},
"main".into()
))
);
assert_eq!(
lex.next().unwrap(),
LeftParen(TokenMetadata {
line: 0,
chars: 9..10
})
);
assert_eq!(
lex.next().unwrap(),
RightParen(TokenMetadata {
line: 0,
chars: 10..11
})
);
assert_eq!(
lex.next().unwrap(),
LeftBrace(TokenMetadata {
line: 0,
chars: 12..13
})
);
assert_eq!(
lex.next().unwrap(),
RightBrace(TokenMetadata {
line: 1,
chars: 0..1
})
);
assert_eq!(lex.next(), None);
}

#[test]
fn glsl_lex_line_comment() {
let source = "void main // myfunction\n//()\n{}";
let mut lex = Lexer::new(source);
fn tokens() {
// line comments
let mut lex = Lexer::new("void main // myfunction\n//()\n{}");
assert_eq!(
lex.next().unwrap(),
Void(TokenMetadata {
Expand Down Expand Up @@ -89,13 +36,9 @@ fn glsl_lex_line_comment() {
})
);
assert_eq!(lex.next(), None);
}

#[test]
fn glsl_lex_multi_line_comment() {
let source = "void main /* comment [] {}\n/**\n{}*/{}";
let mut lex = Lexer::new(source);

// multi line comment
let mut lex = Lexer::new("void main /* comment [] {}\n/**\n{}*/{}");
assert_eq!(
lex.next().unwrap(),
Void(TokenMetadata {
Expand Down Expand Up @@ -128,13 +71,9 @@ fn glsl_lex_multi_line_comment() {
})
);
assert_eq!(lex.next(), None);
}

#[test]
fn glsl_lex_identifier() {
let source = "id123_OK 92No æNoø No¾ No好";
let mut lex = Lexer::new(source);

// identifiers
let mut lex = Lexer::new("id123_OK 92No æNoø No¾ No好");
assert_eq!(
lex.next().unwrap(),
Identifier((
Expand Down Expand Up @@ -236,13 +175,9 @@ fn glsl_lex_identifier() {
))
);
assert_eq!(lex.next(), None);
}

#[test]
fn glsl_lex_version() {
let source = "#version 890 core";
let mut lex = Lexer::new(source);

// version
let mut lex = Lexer::new("#version 890 core");
assert_eq!(
lex.next().unwrap(),
Version(TokenMetadata {
Expand Down Expand Up @@ -271,13 +206,9 @@ fn glsl_lex_version() {
))
);
assert_eq!(lex.next(), None);
}

#[test]
fn glsl_lex_operators() {
let source = "+ - * | & % / += -= *= |= &= %= /= ++ -- || && ^^";
let mut lex = Lexer::new(source);

// operators
let mut lex = Lexer::new("+ - * | & % / += -= *= |= &= %= /= ++ -- || && ^^");
assert_eq!(
lex.next().unwrap(),
Plus(TokenMetadata {
Expand Down
7 changes: 3 additions & 4 deletions src/front/glsl/parser_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fn parse_program(source: &str, stage: ShaderStage) -> Result<Program, ErrorKind>
}

#[test]
fn glsl_parser_version_invalid() {
fn version() {
// invalid versions
assert_eq!(
format!(
"{:?}",
Expand Down Expand Up @@ -47,10 +48,8 @@ fn glsl_parser_version_invalid() {
),
"InvalidProfile(TokenMetadata { line: 0, chars: 13..18 }, \"smart\")"
);
}

#[test]
fn glsl_parser_version_valid() {
// valid versions
let program = parse_program("#version 450\nvoid main() {}", ShaderStage::Vertex).unwrap();
assert_eq!(
format!("{:?}", (program.version, program.profile)),
Expand Down