@@ -5,27 +5,37 @@ use mlua::{Lua, LuaString, Result};
55
66#[ test]
77fn test_string_compare ( ) {
8- fn with_str < F : FnOnce ( LuaString ) > ( s : & str , f : F ) {
9- f ( Lua :: new ( ) . create_string ( s) . unwrap ( ) ) ;
8+ let lua = Lua :: new ( ) ;
9+
10+ fn with_str < F : FnOnce ( LuaString ) > ( lua : & Lua , s : & str , f : F ) {
11+ f ( lua. create_string ( s) . unwrap ( ) ) ;
1012 }
1113
1214 // Tests that all comparisons we want to have are usable
13- with_str ( "teststring" , |t| assert_eq ! ( t, "teststring" ) ) ; // &str
14- with_str ( "teststring" , |t| assert_eq ! ( t, b"teststring" ) ) ; // &[u8]
15- with_str ( "teststring" , |t| assert_eq ! ( t, b"teststring" . to_vec( ) ) ) ; // Vec<u8>
16- with_str ( "teststring" , |t| assert_eq ! ( t, "teststring" . to_string( ) ) ) ; // String
17- with_str ( "teststring" , |t| assert_eq ! ( t, t) ) ; // mlua::String
18- with_str ( "teststring" , |t| assert_eq ! ( t, Cow :: from( b"teststring" . as_ref( ) ) ) ) ; // Cow (borrowed)
19- with_str ( "bla" , |t| assert_eq ! ( t, Cow :: from( b"bla" . to_vec( ) ) ) ) ; // Cow (owned)
15+ with_str ( & lua, "teststring" , |t| assert_eq ! ( t, "teststring" ) ) ; // &str
16+ with_str ( & lua, "teststring" , |t| assert_eq ! ( t, b"teststring" ) ) ; // &[u8]
17+ with_str ( & lua, "teststring" , |t| assert_eq ! ( t, b"teststring" . to_vec( ) ) ) ; // Vec<u8>
18+ with_str ( & lua, "teststring" , |t| assert_eq ! ( t, "teststring" . to_string( ) ) ) ; // String
19+ with_str ( & lua, "teststring" , |t| assert_eq ! ( t, t) ) ; // mlua::String
20+ with_str ( & lua, "teststring" , |t| {
21+ assert_eq ! ( t, Cow :: from( b"teststring" . as_ref( ) ) ) // Cow (borrowed)
22+ } ) ;
23+ with_str ( & lua, "bla" , |t| assert_eq ! ( t, Cow :: from( b"bla" . to_vec( ) ) ) ) ; // Cow (owned)
2024
2125 // Test ordering
22- with_str ( "a" , |a| {
26+ with_str ( & lua , "a" , |a| {
2327 assert ! ( !( a < a) ) ;
2428 assert ! ( !( a > a) ) ;
2529 } ) ;
26- with_str ( "a" , |a| assert ! ( a < "b" ) ) ;
27- with_str ( "a" , |a| assert ! ( a < b"b" ) ) ;
28- with_str ( "a" , |a| with_str ( "b" , |b| assert ! ( a < b) ) ) ;
30+ with_str ( & lua, "a" , |a| assert ! ( a < "b" ) ) ;
31+ with_str ( & lua, "a" , |a| assert ! ( a < b"b" ) ) ;
32+ with_str ( & lua, "a" , |a| with_str ( & lua, "b" , |b| assert ! ( a < b) ) ) ;
33+
34+ // Long strings (not interned by Lua)
35+ let long_str = "abc" . repeat ( 100 ) ;
36+ with_str ( & lua, & long_str, |s1| {
37+ with_str ( & lua, & long_str, |s2| assert_eq ! ( s1, s2) )
38+ } ) ;
2939}
3040
3141#[ test]
0 commit comments