@@ -1904,4 +1904,102 @@ end
19041904"#
19051905 ) ;
19061906 }
1907+
1908+ // ========== LuaJIT extension: const ==========
1909+
1910+ #[ test]
1911+ fn test_const_stat_format ( ) {
1912+ use crate :: format_text;
1913+ use emmylua_parser:: LuaLanguageLevel ;
1914+ let config = LuaFormatConfig :: default ( ) ;
1915+ let input = "const x = 1\n " ;
1916+ let expected = "const x = 1\n " ;
1917+ let result = format_text ( input, LuaLanguageLevel :: LuaJITExt , & config) . formatted ;
1918+ assert_eq ! ( result, expected) ;
1919+ }
1920+
1921+ #[ test]
1922+ fn test_const_stat_assign_format ( ) {
1923+ use crate :: format_text;
1924+ use emmylua_parser:: LuaLanguageLevel ;
1925+ let config = LuaFormatConfig :: default ( ) ;
1926+ let input = "const a,b = 1,2\n " ;
1927+ let expected = "const a, b = 1, 2\n " ;
1928+ let result = format_text ( input, LuaLanguageLevel :: LuaJITExt , & config) . formatted ;
1929+ assert_eq ! ( result, expected) ;
1930+ }
1931+
1932+ // ========== LuaJIT extension: continue ==========
1933+
1934+ #[ test]
1935+ fn test_continue_stat_format ( ) {
1936+ use crate :: format_text;
1937+ use emmylua_parser:: LuaLanguageLevel ;
1938+ let config = LuaFormatConfig :: default ( ) ;
1939+ let input = "while true do\n if x then\n continue\n end\n end\n " ;
1940+ let expected = "while true do\n if x then\n continue\n end\n end\n " ;
1941+ let result = format_text ( input, LuaLanguageLevel :: LuaJITExt , & config) . formatted ;
1942+ assert_eq ! ( result, expected) ;
1943+ }
1944+
1945+ // ========== LuaJIT extension: ternary ==========
1946+
1947+ #[ test]
1948+ fn test_ternary_format_inline ( ) {
1949+ use crate :: format_text;
1950+ use emmylua_parser:: LuaLanguageLevel ;
1951+ let config = LuaFormatConfig :: default ( ) ;
1952+ let input = "local x = a ? b : c\n " ;
1953+ let expected = "local x = a ? b : c\n " ;
1954+ let result = format_text ( input, LuaLanguageLevel :: LuaJITExt , & config) . formatted ;
1955+ assert_eq ! ( result, expected) ;
1956+ }
1957+
1958+ #[ test]
1959+ fn test_ternary_format_nested ( ) {
1960+ use crate :: format_text;
1961+ use emmylua_parser:: LuaLanguageLevel ;
1962+ let config = LuaFormatConfig :: default ( ) ;
1963+ let input = "local x = a ? b ? c : d : e\n " ;
1964+ let expected = "local x = a ? b ? c : d : e\n " ;
1965+ let result = format_text ( input, LuaLanguageLevel :: LuaJITExt , & config) . formatted ;
1966+ assert_eq ! ( result, expected) ;
1967+ }
1968+
1969+ // ========== LuaJIT extension: safe navigation ==========
1970+
1971+ #[ test]
1972+ fn test_safe_navigation_dot_format ( ) {
1973+ use crate :: format_text;
1974+ use emmylua_parser:: LuaLanguageLevel ;
1975+ let config = LuaFormatConfig :: default ( ) ;
1976+ let input = "local x = obj?.field\n " ;
1977+ let expected = "local x = obj?.field\n " ;
1978+ let result = format_text ( input, LuaLanguageLevel :: LuaJITExt , & config) . formatted ;
1979+ assert_eq ! ( result, expected) ;
1980+ }
1981+
1982+ // ========== LuaJIT extension: nil-coalescing ==========
1983+
1984+ #[ test]
1985+ fn test_nil_coalescing_format ( ) {
1986+ use crate :: format_text;
1987+ use emmylua_parser:: LuaLanguageLevel ;
1988+ let config = LuaFormatConfig :: default ( ) ;
1989+ let input = "local x = a ?? b\n " ;
1990+ let expected = "local x = a ?? b\n " ;
1991+ let result = format_text ( input, LuaLanguageLevel :: LuaJITExt , & config) . formatted ;
1992+ assert_eq ! ( result, expected) ;
1993+ }
1994+
1995+ #[ test]
1996+ fn test_nil_coalescing_chain_format ( ) {
1997+ use crate :: format_text;
1998+ use emmylua_parser:: LuaLanguageLevel ;
1999+ let config = LuaFormatConfig :: default ( ) ;
2000+ let input = "local x = a ?? b ?? c\n " ;
2001+ let expected = "local x = a ?? b ?? c\n " ;
2002+ let result = format_text ( input, LuaLanguageLevel :: LuaJITExt , & config) . formatted ;
2003+ assert_eq ! ( result, expected) ;
2004+ }
19072005}
0 commit comments