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 1 commit
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
66 changes: 6 additions & 60 deletions src/front/glsl/lex_tests.rs
Original file line number Diff line number Diff line change
@@ -1,60 +1,8 @@
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() {
fn comments() {
// line comments
let source = "void main // myfunction\n//()\n{}";
let mut lex = Lexer::new(source);
assert_eq!(
Expand Down Expand Up @@ -89,10 +37,8 @@ fn glsl_lex_line_comment() {
})
);
assert_eq!(lex.next(), None);
}

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

Expand Down Expand Up @@ -131,7 +77,7 @@ fn glsl_lex_multi_line_comment() {
}

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

Expand Down Expand Up @@ -239,7 +185,7 @@ fn glsl_lex_identifier() {
}

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

Expand Down Expand Up @@ -274,7 +220,7 @@ fn glsl_lex_version() {
}

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

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