diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da53f178..d54e4461 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,12 @@ jobs: - name: Test (Lua 5.2) run: cargo test --features lua52 + - name: Test (Lua 5.3) + run: cargo test --features lua53 + + - name: Test (Lua 5.4) + run: cargo test --features lua54 + - name: Test Build (wasm) run: | rustup target add wasm32-unknown-unknown diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b8760c..e2aa66b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added support for Lua 5.3, gated behind the `lua53` feature flag ([#534](https://github.com/JohnnyMorganz/StyLua/issues/534)) +- Added support for Lua 5.4, gated behind the `lua54` feature flag ([#533](https://github.com/JohnnyMorganz/StyLua/issues/533)) - Added `--allow-hidden` flag to allow entering and formatting hidden files/directories ([#562](https://github.com/JohnnyMorganz/StyLua/issues/562)) - Added `--output-format=summary` which can be used with `--check` to output a summary of the list of files not correctly formatted ([#573](https://github.com/JohnnyMorganz/StyLua/issues/573)) diff --git a/Cargo.lock b/Cargo.lock index 0a110b2a..9047c593 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,6 +48,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + [[package]] name = "bitflags" version = "1.3.2" @@ -317,25 +323,25 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "full_moon" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf176fa61b7bfd03d311cf17618bb8cb16115e9077ab591a847c3437c8a6001" +checksum = "043b0dacc57e32aada47d0ba75baa31cf079e3297fa4fb32575791fda616f968" dependencies = [ "bytecount", "cfg-if", "derive_more", "full_moon_derive", + "logos", "paste", - "peg", "serde", "smol_str", ] [[package]] name = "full_moon_derive" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87826a47a649663aa287e57ea9f31450a56fabcd553a2fe17b2f669f1b5e855b" +checksum = "99b4bd12ce56927d1dc5478d21528ea8c4b93ca85ff8f8043b6a5351a2a3c6f7" dependencies = [ "indexmap", "proc-macro2", @@ -484,6 +490,29 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "logos" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-derive" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c" +dependencies = [ + "beef", + "fnv", + "proc-macro2", + "quote", + "regex-syntax", + "syn", +] + [[package]] name = "memchr" version = "2.4.1" @@ -558,33 +587,6 @@ dependencies = [ "proc-macro-hack", ] -[[package]] -name = "peg" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07c0b841ea54f523f7aa556956fbd293bcbe06f2e67d2eb732b7278aaf1d166a" -dependencies = [ - "peg-macros", - "peg-runtime", -] - -[[package]] -name = "peg-macros" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aa52829b8decbef693af90202711348ab001456803ba2a98eb4ec8fb70844c" -dependencies = [ - "peg-runtime", - "proc-macro2", - "quote", -] - -[[package]] -name = "peg-runtime" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c719dcf55f09a3a7e764c6649ab594c18a177e3599c467983cdf644bfc0a4088" - [[package]] name = "pest" version = "2.1.3" diff --git a/Cargo.toml b/Cargo.toml index 66d356e8..73f426dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,8 @@ bench = false default = [] luau = ["full_moon/roblox"] lua52 = ["full_moon/lua52"] +lua53 = ["lua52", "full_moon/lua53"] +lua54 = ["lua53", "full_moon/lua54"] [dependencies] anyhow = "1.0.53" @@ -34,7 +36,7 @@ clap = { version = "3.1.6", features = ["derive"] } console = "0.15.0" crossbeam-channel = "0.5.4" env_logger = { version = "0.9.0", default-features = false } -full_moon = "0.15.1" +full_moon = "0.16.0" globset = "0.4.8" ignore = "0.4.18" lazy_static = "1.4.0" diff --git a/README.md b/README.md index 2d577db7..91c6d4ae 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ -An opinionated code formatter for Lua 5.1, Lua 5.2 and [Luau](https://roblox.github.io/luau/), built using [full-moon](https://github.com/Kampfkarren/full-moon). +An opinionated code formatter for Lua 5.1, 5.2, 5.3, 5.4 and [Luau](https://roblox.github.io/luau/), built using [full-moon](https://github.com/Kampfkarren/full-moon). StyLua is inspired by the likes of [prettier](https://github.com/prettier/prettier), it parses your Lua codebase, and prints it back out from scratch, enforcing a consistent code style. @@ -19,18 +19,20 @@ There are multiple ways to install StyLua: Pre-built binaries are available on the [GitHub Releases Page](https://github.com/JohnnyMorganz/StyLua/releases). -By default, these are built with **both Luau and Lua 5.2 features enabled**, to cover all possible codebases. +By default, these are built with **all syntax variants enabled (Lua 5.2, 5.3, 5.4 and Luau)**, to cover all possible codebases. If you would like to format a specific Lua version only, see [installing from crates.io](#from-cratesio). ### From Crates.io If you have [Rust](https://www.rust-lang.org/) installed, you can install StyLua using cargo. By default, this builds for just Lua 5.1. -You can pass the `--features ` argument to build for Lua 5.2 (`lua52`) or Luau (`luau`) +You can pass the `--features ` argument to build for Lua 5.2 (`lua52`), Lua 5.3 (`lua53`), Lua 5.4 (`lua54`) or Luau (`luau`) ```sh cargo install stylua cargo install stylua --features lua52 +cargo install stylua --features lua53 +cargo install stylua --features lua54 cargo install stylua --features luau ``` diff --git a/src/formatters/assignment.rs b/src/formatters/assignment.rs index f28f3164..0c7532fc 100644 --- a/src/formatters/assignment.rs +++ b/src/formatters/assignment.rs @@ -9,6 +9,8 @@ use full_moon::{ tokenizer::TokenType, }; +#[cfg(feature = "lua54")] +use crate::formatters::lua54::format_attribute; #[cfg(feature = "luau")] use crate::formatters::luau::format_type_specifier; use crate::{ @@ -386,6 +388,12 @@ fn format_local_no_assignment( Some(1), ); + #[cfg(feature = "lua54")] + let attributes = assignment + .attributes() + .map(|x| x.map(|attribute| format_attribute(ctx, attribute, shape))) + .collect(); + #[cfg(feature = "luau")] let type_specifiers: Vec> = assignment .type_specifiers() @@ -393,6 +401,8 @@ fn format_local_no_assignment( .collect(); let local_assignment = LocalAssignment::new(name_list); + #[cfg(feature = "lua54")] + let local_assignment = local_assignment.with_attributes(attributes); #[cfg(feature = "luau")] let local_assignment = local_assignment.with_type_specifiers(type_specifiers); @@ -439,21 +449,31 @@ pub fn format_local_assignment_no_trivia( format_expression, ); + #[cfg(feature = "lua54")] + let attributes: Vec> = assignment + .attributes() + .map(|x| x.map(|attribute| format_attribute(ctx, attribute, shape))) + .collect(); + #[cfg(feature = "luau")] let type_specifiers: Vec> = assignment .type_specifiers() .map(|x| x.map(|type_specifier| format_type_specifier(ctx, type_specifier, shape))) .collect(); - let type_specifier_len; - #[cfg(feature = "luau")] + + #[allow(unused_mut)] + let mut type_specifier_len = 0; + #[cfg(feature = "lua54")] { - type_specifier_len = type_specifiers.iter().fold(0, |acc, x| { + type_specifier_len += attributes.iter().fold(0, |acc, x| { acc + x.as_ref().map_or(0, |y| y.to_string().len()) }); } - #[cfg(not(feature = "luau"))] + #[cfg(feature = "luau")] { - type_specifier_len = 0; + type_specifier_len += type_specifiers.iter().fold(0, |acc, x| { + acc + x.as_ref().map_or(0, |y| y.to_string().len()) + }); } // Test the assignment to see if its over width @@ -483,6 +503,8 @@ pub fn format_local_assignment_no_trivia( } let local_assignment = LocalAssignment::new(name_list); + #[cfg(feature = "lua54")] + let local_assignment = local_assignment.with_attributes(attributes); #[cfg(feature = "luau")] let local_assignment = local_assignment.with_type_specifiers(type_specifiers); local_assignment diff --git a/src/formatters/expression.rs b/src/formatters/expression.rs index 0b3005a1..f2d3c32f 100644 --- a/src/formatters/expression.rs +++ b/src/formatters/expression.rs @@ -35,12 +35,13 @@ use crate::{ #[macro_export] macro_rules! fmt_op { - ($ctx:expr, $enum:ident, $value:ident, $shape:expr, { $($operator:ident = $output:expr,)+ }) => { + ($ctx:expr, $enum:ident, $value:ident, $shape:expr, { $($(#[$inner:meta])* $operator:ident = $output:expr,)+ }, $other:expr) => { match $value { $( + $(#[$inner])* $enum::$operator(token) => $enum::$operator(fmt_symbol!($ctx, token, $output, $shape)), )+ - other => panic!("unknown node {:?}", other), + other => $other(other), } }; } @@ -79,6 +80,26 @@ pub fn format_binop(ctx: &Context, binop: &BinOp, shape: Shape) -> BinOp { TildeEqual = " ~= ", TwoDots = " .. ", TwoEqual = " == ", + #[cfg(feature = "lua53")] + Ampersand = " & ", + #[cfg(feature = "lua53")] + DoubleSlash = " // ", + #[cfg(feature = "lua53")] + DoubleLessThan = " << ", + #[cfg(feature = "lua53")] + Pipe = " | ", + #[cfg(feature = "lua53")] + Tilde = " ~ ", + }, |other: &BinOp| match other { + #[cfg(feature = "lua53")] + BinOp::DoubleGreaterThan(token) => BinOp::DoubleGreaterThan( + format_token_reference(ctx, token, shape) + .update_trivia( + FormatTriviaType::Append(vec![Token::new(TokenType::spaces(1))]), + FormatTriviaType::Append(vec![Token::new(TokenType::spaces(1))]) + ) + ), + other => panic!("unknown node {:?}", other) }) } @@ -793,7 +814,9 @@ pub fn format_unop(ctx: &Context, unop: &UnOp, shape: Shape) -> UnOp { Minus = "-", Not = "not ", Hash = "#", - }) + #[cfg(feature = "lua53")] + Tilde = "~", + }, |other| panic!("unknown node {:?}", other)) } /// Pushes a [`BinOp`] onto a newline, and indent its depending on indent_level. diff --git a/src/formatters/lua54.rs b/src/formatters/lua54.rs new file mode 100644 index 00000000..36e0192a --- /dev/null +++ b/src/formatters/lua54.rs @@ -0,0 +1,21 @@ +use crate::{ + context::Context, + formatters::{ + general::{format_contained_span, format_token_reference}, + trivia::{FormatTriviaType, UpdateLeadingTrivia}, + }, + shape::Shape, +}; +use full_moon::{ + ast::lua54::Attribute, + tokenizer::{Token, TokenType}, +}; + +pub fn format_attribute(ctx: &Context, attribute: &Attribute, shape: Shape) -> Attribute { + let brackets = format_contained_span(ctx, attribute.brackets(), shape).update_leading_trivia( + FormatTriviaType::Append(vec![Token::new(TokenType::spaces(1))]), + ); + let name = format_token_reference(ctx, attribute.name(), shape); + + Attribute::new(name).with_brackets(brackets) +} diff --git a/src/formatters/luau.rs b/src/formatters/luau.rs index 8e27c943..f88f1755 100644 --- a/src/formatters/luau.rs +++ b/src/formatters/luau.rs @@ -41,7 +41,7 @@ pub fn format_compound_op(ctx: &Context, compound_op: &CompoundOp, shape: Shape) PercentEqual = " %= ", CaretEqual = " ^= ", TwoDotsEqual = " ..= ", - }) + }, |other| panic!("unknown node {:?}", other)) } pub fn format_compound_assignment( diff --git a/src/formatters/mod.rs b/src/formatters/mod.rs index 4deb13ab..642fe700 100644 --- a/src/formatters/mod.rs +++ b/src/formatters/mod.rs @@ -9,6 +9,8 @@ pub mod expression; pub mod functions; #[cfg(feature = "lua52")] pub mod lua52; +#[cfg(feature = "lua54")] +pub mod lua54; #[cfg(feature = "luau")] pub mod luau; pub mod stmt; diff --git a/src/formatters/trivia.rs b/src/formatters/trivia.rs index 7981bd22..407ff046 100644 --- a/src/formatters/trivia.rs +++ b/src/formatters/trivia.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "lua54")] +use full_moon::ast::lua54::Attribute; #[cfg(feature = "luau")] use full_moon::ast::types::{ ElseIfExpression, GenericDeclaration, GenericDeclarationParameter, GenericParameterInfo, @@ -158,9 +160,10 @@ macro_rules! define_update_trailing_trivia { } macro_rules! binop_trivia { - ($enum:ident, $value:ident, $leading_trivia:ident, $trailing_trivia:ident, { $($operator:ident,)+ }) => { + ($enum:ident, $value:ident, $leading_trivia:ident, $trailing_trivia:ident, { $($(#[$inner:meta])* $operator:ident,)+ }) => { match $value { $( + $(#[$inner])* $enum::$operator(token) => $enum::$operator(token.update_trivia($leading_trivia, $trailing_trivia)), )+ other => panic!("unknown node {:?}", other), @@ -185,6 +188,18 @@ define_update_trivia!(BinOp, |this, leading, trailing| { TildeEqual, TwoDots, TwoEqual, + #[cfg(feature = "lua53")] + Ampersand, + #[cfg(feature = "lua53")] + DoubleSlash, + #[cfg(feature = "lua53")] + DoubleLessThan, + #[cfg(feature = "lua53")] + Pipe, + #[cfg(feature = "lua53")] + DoubleGreaterThan, + #[cfg(feature = "lua53")] + Tilde, }) }); @@ -477,6 +492,12 @@ define_update_trivia!(Assignment, |this, leading, trailing| { .with_expressions(this.expressions().update_trailing_trivia(trailing)) }); +#[cfg(feature = "lua54")] +define_update_trivia!(Attribute, |this, leading, trailing| { + this.to_owned() + .with_brackets(this.brackets().update_trivia(leading, trailing)) +}); + define_update_trivia!(LocalAssignment, |this, leading, trailing| { if this.expressions().is_empty() { // Handle if the last item had a type specifier set @@ -494,6 +515,20 @@ define_update_trivia!(LocalAssignment, |this, leading, trailing| { } ); + cfg_if::cfg_if!( + if #[cfg(feature = "lua54")] { + let mut attributes = this.attributes().map(|x| x.cloned()).collect::>(); + + if let Some(Some(attribute)) = attributes.pop() { + attributes.push(Some(attribute.update_trailing_trivia(trailing))); + + return this.clone() + .with_local_token(this.local_token().update_leading_trivia(leading)) + .with_attributes(attributes); + } + } + ); + this.clone() .with_local_token(this.local_token().update_leading_trivia(leading)) .with_names(this.names().update_trailing_trivia(trailing)) @@ -643,6 +678,8 @@ define_update_leading_trivia!(UnOp, |this, leading| { UnOp::Hash(token_reference) => UnOp::Hash(token_reference.update_leading_trivia(leading)), UnOp::Minus(token_reference) => UnOp::Minus(token_reference.update_leading_trivia(leading)), UnOp::Not(token_reference) => UnOp::Not(token_reference.update_leading_trivia(leading)), + #[cfg(feature = "lua53")] + UnOp::Tilde(token_reference) => UnOp::Tilde(token_reference.update_leading_trivia(leading)), other => panic!("unknown node {:?}", other), } }); diff --git a/src/formatters/trivia_util.rs b/src/formatters/trivia_util.rs index f5038b24..4a8ed43d 100644 --- a/src/formatters/trivia_util.rs +++ b/src/formatters/trivia_util.rs @@ -8,12 +8,13 @@ use full_moon::ast::span::ContainedSpan; #[cfg(feature = "luau")] use full_moon::ast::types::{ GenericDeclarationParameter, GenericParameterInfo, IndexedTypeInfo, TypeArgument, - TypeDeclaration, TypeInfo, + TypeDeclaration, TypeInfo, TypeSpecifier, }; use full_moon::{ ast::{ punctuated::Punctuated, BinOp, Block, Call, Expression, Field, FunctionArgs, Index, - LastStmt, Parameter, Prefix, Stmt, Suffix, TableConstructor, UnOp, Value, Var, + LastStmt, LocalAssignment, Parameter, Prefix, Stmt, Suffix, TableConstructor, UnOp, Value, + Var, }, node::Node, tokenizer::{Token, TokenKind, TokenReference, TokenType}, @@ -372,6 +373,8 @@ pub fn get_expression_leading_trivia(expression: &Expression) -> Vec { UnOp::Minus(token_ref) | UnOp::Not(token_ref) | UnOp::Hash(token_ref) => { token_ref.leading_trivia().map(|x| x.to_owned()).collect() } + #[cfg(feature = "lua53")] + UnOp::Tilde(token_ref) => token_ref.leading_trivia().cloned().collect(), other => panic!("unknown node {:?}", other), }, Expression::BinaryOperator { lhs, .. } => get_expression_leading_trivia(lhs), @@ -448,6 +451,17 @@ pub fn binop_leading_comments(binop: &BinOp) -> Vec { .filter(|token| trivia_is_comment(token)) .map(|x| x.to_owned()) .collect(), + #[cfg(feature = "lua53")] + BinOp::Ampersand(token) + | BinOp::DoubleSlash(token) + | BinOp::DoubleLessThan(token) + | BinOp::Pipe(token) + | BinOp::DoubleGreaterThan(token) + | BinOp::Tilde(token) => token + .leading_trivia() + .filter(|token| trivia_is_comment(token)) + .cloned() + .collect(), other => panic!("unknown node {:?}", other), } } @@ -478,6 +492,20 @@ pub fn binop_trailing_comments(binop: &BinOp) -> Vec { }) .collect() } + #[cfg(feature = "lua53")] + BinOp::Ampersand(token) + | BinOp::DoubleSlash(token) + | BinOp::DoubleLessThan(token) + | BinOp::Pipe(token) + | BinOp::DoubleGreaterThan(token) + | BinOp::Tilde(token) => token + .trailing_trivia() + .filter(|token| trivia_is_comment(token)) + .flat_map(|x| { + // Prepend a single space beforehand + vec![Token::new(TokenType::spaces(1)), x.to_owned()] + }) + .collect(), other => panic!("unknown node {:?}", other), } } @@ -864,6 +892,81 @@ fn get_type_declaration_trailing_trivia( ) } +#[cfg(feature = "luau")] +fn type_specifier_trailing_trivia(type_specifier: &TypeSpecifier) -> Vec { + get_type_info_trailing_trivia(type_specifier.type_info().clone()).1 +} + +fn get_empty_local_assignment_trailing_trivia( + local_assignment: LocalAssignment, +) -> (LocalAssignment, Vec) { + let mut trailing_trivia = Vec::new(); + + #[cfg(feature = "luau")] + { + let mut type_specifiers = local_assignment + .type_specifiers() + .map(|x| x.cloned()) + .collect::>(); + + if let Some(Some(type_specifier)) = type_specifiers.pop() { + trailing_trivia = type_specifier_trailing_trivia(&type_specifier); + + type_specifiers.push(Some( + type_specifier.update_trailing_trivia(FormatTriviaType::Replace(vec![])), + )); + + return ( + local_assignment.with_type_specifiers(type_specifiers), + trailing_trivia, + ); + } + } + + #[cfg(feature = "lua54")] + { + let mut attributes = local_assignment + .attributes() + .map(|x| x.cloned()) + .collect::>(); + + if let Some(Some(attribute)) = attributes.pop() { + trailing_trivia = attribute + .brackets() + .tokens() + .1 + .trailing_trivia() + .cloned() + .collect(); + + attributes.push(Some( + attribute.update_trailing_trivia(FormatTriviaType::Replace(vec![])), + )); + + return ( + local_assignment.with_attributes(attributes), + trailing_trivia, + ); + } + } + + // Unassigned local variable + let mut formatted_name_list = local_assignment.names().to_owned(); + // Retrieve last item and take its trailing comments + if let Some(last_pair) = formatted_name_list.pop() { + let pair = last_pair.map(|value| { + trailing_trivia = value.trailing_trivia().map(|x| x.to_owned()).collect(); + value.update_trailing_trivia(FormatTriviaType::Replace(vec![])) + }); + formatted_name_list.push(pair); + } + + ( + local_assignment.with_names(formatted_name_list), + trailing_trivia, + ) +} + pub fn get_stmt_trailing_trivia(stmt: Stmt) -> (Stmt, Vec) { let (updated_stmt, trailing_trivia) = match stmt { Stmt::Assignment(assignment) => { @@ -886,17 +989,10 @@ pub fn get_stmt_trailing_trivia(stmt: Stmt) -> (Stmt, Vec) { Stmt::LocalAssignment(local_assignment) => { let mut trailing_trivia = Vec::new(); let new_assignment = if local_assignment.expressions().is_empty() { - // Unassigned local variable - let mut formatted_name_list = local_assignment.names().to_owned(); - // Retrieve last item and take its trailing comments - if let Some(last_pair) = formatted_name_list.pop() { - let pair = last_pair.map(|value| { - trailing_trivia = value.trailing_trivia().map(|x| x.to_owned()).collect(); - value.update_trailing_trivia(FormatTriviaType::Replace(vec![])) - }); - formatted_name_list.push(pair); - } - local_assignment.with_names(formatted_name_list) + let (assignment, trivia) = + get_empty_local_assignment_trailing_trivia(local_assignment); + trailing_trivia = trivia; + assignment } else { // Add newline at the end of LocalAssignment expression list // Expression list should already be formatted diff --git a/tests/inputs-lua53/binary-operators.lua b/tests/inputs-lua53/binary-operators.lua new file mode 100644 index 00000000..3593689e --- /dev/null +++ b/tests/inputs-lua53/binary-operators.lua @@ -0,0 +1,6 @@ +local a = 1 & 2 +local b = 1 | 2 +local c = 1 << 2 +local d = 1 >> 2 +local e = 1 ~ 2 +local f = 1 // 2 diff --git a/tests/inputs-lua53/unary-operators.lua b/tests/inputs-lua53/unary-operators.lua new file mode 100644 index 00000000..ed803461 --- /dev/null +++ b/tests/inputs-lua53/unary-operators.lua @@ -0,0 +1 @@ +local x = ~1 diff --git a/tests/inputs-lua54/attributes-1.lua b/tests/inputs-lua54/attributes-1.lua new file mode 100644 index 00000000..2979db1e --- /dev/null +++ b/tests/inputs-lua54/attributes-1.lua @@ -0,0 +1,5 @@ +local a = 5 +local d +local e , f = 1, 2 +local g , h +local i , j, k diff --git a/tests/snapshots/tests__lua53@binary-operators.lua.snap b/tests/snapshots/tests__lua53@binary-operators.lua.snap new file mode 100644 index 00000000..30ff8905 --- /dev/null +++ b/tests/snapshots/tests__lua53@binary-operators.lua.snap @@ -0,0 +1,11 @@ +--- +source: tests/tests.rs +expression: format(&contents) +--- +local a = 1 & 2 +local b = 1 | 2 +local c = 1 << 2 +local d = 1 >> 2 +local e = 1 ~ 2 +local f = 1 // 2 + diff --git a/tests/snapshots/tests__lua53@unary-operators.lua.snap b/tests/snapshots/tests__lua53@unary-operators.lua.snap new file mode 100644 index 00000000..e660cb68 --- /dev/null +++ b/tests/snapshots/tests__lua53@unary-operators.lua.snap @@ -0,0 +1,6 @@ +--- +source: tests/tests.rs +expression: format(&contents) +--- +local x = ~1 + diff --git a/tests/snapshots/tests__lua54@attributes-1.lua.snap b/tests/snapshots/tests__lua54@attributes-1.lua.snap new file mode 100644 index 00000000..338bc103 --- /dev/null +++ b/tests/snapshots/tests__lua54@attributes-1.lua.snap @@ -0,0 +1,10 @@ +--- +source: tests/tests.rs +expression: format(&contents) +--- +local a = 5 +local d +local e , f = 1, 2 +local g , h +local i , j, k + diff --git a/tests/tests.rs b/tests/tests.rs index e5066ee4..51fdc674 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -26,6 +26,7 @@ fn test_full_moon_test_suite() { #[cfg(feature = "luau")] fn test_luau() { insta::glob!("inputs-luau/*.lua", |path| { + dbg!(path); let contents = std::fs::read_to_string(path).unwrap(); insta::assert_snapshot!(format(&contents)); }) @@ -49,6 +50,24 @@ fn test_lua52() { }) } +#[test] +#[cfg(feature = "lua53")] +fn test_lua53() { + insta::glob!("inputs-lua53/*.lua", |path| { + let contents = std::fs::read_to_string(path).unwrap(); + insta::assert_snapshot!(format(&contents)); + }) +} + +#[test] +#[cfg(feature = "lua54")] +fn test_lua54() { + insta::glob!("inputs-lua54/*.lua", |path| { + let contents = std::fs::read_to_string(path).unwrap(); + insta::assert_snapshot!(format(&contents)); + }) +} + #[test] fn test_ignores() { insta::glob!("inputs-ignore/*.lua", |path| {