use pasta_dsl::parse_str;
use pasta_lua::LuaTranspiler;
const PASTA_WITH_CUE: &str = r#"
*起動挨拶
さくら:こんにちは!
!wait@さくら(500)
うにゅう:やあ!
!bgm(morning.ogg)
$score=100
"#;
#[test]
fn test_transpile_scene_with_cue_commands_succeeds() {
let file = parse_str(PASTA_WITH_CUE, "test.pasta").unwrap();
let transpiler = LuaTranspiler::default();
let mut output = Vec::new();
let result = transpiler.transpile(&file, &mut output);
assert!(
result.is_ok(),
"Transpilation should succeed for scenes with cue commands: {:?}",
result.err()
);
}
#[test]
fn test_cue_commands_not_emitted_in_lua_output() {
let file = parse_str(PASTA_WITH_CUE, "test.pasta").unwrap();
let transpiler = LuaTranspiler::default();
let mut output = Vec::new();
transpiler.transpile(&file, &mut output).unwrap();
let lua_code = String::from_utf8(output).unwrap();
assert!(
!lua_code.contains("!wait"),
"CueCommand '!wait' should not appear in Lua output"
);
assert!(
!lua_code.contains("!bgm"),
"CueCommand '!bgm' should not appear in Lua output"
);
}
#[test]
fn test_non_cue_items_emitted_correctly_alongside_cue() {
let file = parse_str(PASTA_WITH_CUE, "test.pasta").unwrap();
let transpiler = LuaTranspiler::default();
let mut output = Vec::new();
transpiler.transpile(&file, &mut output).unwrap();
let lua_code = String::from_utf8(output).unwrap();
assert!(
lua_code.contains("act.さくら:talk"),
"Action line for さくら should be emitted"
);
assert!(
lua_code.contains("act.うにゅう:talk"),
"Action line for うにゅう should be emitted"
);
assert!(
lua_code.contains("var.score"),
"Variable set should be emitted"
);
}
#[test]
fn test_transpile_fullwidth_cue_marker_passthrough() {
let pasta = "*テスト\n さくら:はい\n !effect(flash)\n さくら:終了\n";
let file = parse_str(pasta, "test.pasta").unwrap();
let transpiler = LuaTranspiler::default();
let mut output = Vec::new();
let result = transpiler.transpile(&file, &mut output);
assert!(
result.is_ok(),
"Transpilation should succeed with fullwidth cue marker"
);
let lua_code = String::from_utf8(output).unwrap();
assert!(
!lua_code.contains("!effect"),
"Fullwidth cue command should not appear in Lua output"
);
assert!(
lua_code.contains("act.さくら:talk"),
"Action lines should still be emitted"
);
}
#[test]
fn test_transpile_requirements_sample_scene() {
let pasta = r#"
*起動挨拶
さくら:こんにちは!
!wait@さくら(500)
!bgm(morning.ogg)
うにゅう:やあ!
"#;
let file = parse_str(pasta, "test.pasta").unwrap();
let transpiler = LuaTranspiler::default();
let mut output = Vec::new();
let result = transpiler.transpile(&file, &mut output);
assert!(
result.is_ok(),
"Requirements sample should transpile: {:?}",
result.err()
);
let lua_code = String::from_utf8(output).unwrap();
assert!(
lua_code.contains("PASTA.create_scene"),
"Scene should be created"
);
assert!(
lua_code.contains("act.さくら:talk"),
"Action lines should be present"
);
assert!(
lua_code.contains("act.うにゅう:talk"),
"All action lines should be present"
);
}