git.delta.rocks / jrsonnet / refs/commits / 000d927bc641

difftreelog

test fix

Yaroslav Bolyukin2024-03-03parent: #0764805.patch.diff
in: master

6 files changed

modifiedcmds/jrsonnet-fmt/src/snapshots/jrsonnet_fmt__tests__complex_comments_snapshot.snapdiffbeforeafterboth
--- a/cmds/jrsonnet-fmt/src/snapshots/jrsonnet_fmt__tests__complex_comments_snapshot.snap
+++ b/cmds/jrsonnet-fmt/src/snapshots/jrsonnet_fmt__tests__complex_comments_snapshot.snap
@@ -3,51 +3,51 @@
 expression: "reformat(indoc!(\"{\n\t\t  comments: {\n\t\t\t_: '',\n\t\t\t//     Plain comment\n\t\t\ta: '',\n\n\t\t\t#    Plain comment with empty line before\n\t\t\tb: '',\n\t\t\t/*Single-line multiline comment\n\n\t\t\t*/\n\t\t\tc: '',\n\n\t\t\t/**Single-line multiline doc comment\n\n\t\t\t*/\n\t\t\tc: '',\n\n\t\t\t/**Multiline doc\n\t\t\tComment\n\t\t\t*/\n\t\t\tc: '',\n\n\t\t\t/*\n\n\tMulti-line\n\n\tcomment\n\t\t\t*/\n\t\t\td: '',\n\n\t\t\te: '', // Inline comment\n\n\t\t\tk: '',\n\n\t\t\t// Text after everything\n\t\t  },\n\t\t  comments2: {\n\t\t\tk: '',\n\t\t\t// Text after everything, but no newline above\n\t\t  },\n          spacing: {\n            a: '',\n\n            b: '',\n          },\n          noSpacing: {\n            a: '',\n            b: '',\n          },\n        }\"))"
 ---
 {
-  comments: {
-    _: '',
-    // Plain comment
-    a: '',
+	comments: {
+		_: '',
+		// Plain comment
+		a: '',
 
-    # Plain comment with empty line before
-    b: '',
-    /* Single-line multiline comment */
-    c: '',
+		# Plain comment with empty line before
+		b: '',
+		/* Single-line multiline comment */
+		c: '',
 
-    /**
-     * Single-line multiline doc comment
-     */
-    c: '',
+		/**
+		 * Single-line multiline doc comment
+		 */
+		c: '',
 
-    /**
-     * Multiline doc
-     * Comment
-     */
-    c: '',
+		/**
+		 * Multiline doc
+		 * Comment
+		 */
+		c: '',
 
-    /*
-    Multi-line
+		/*
+		Multi-line
 
-    comment
-    */
-    d: '',
+		comment
+		*/
+		d: '',
 
-    e: '', // Inline comment
+		e: '', // Inline comment
 
-    k: '',
+		k: '',
 
-    // Text after everything
-  },
-  comments2: {
-    k: '',
-    // Text after everything, but no newline above
-  },
-  spacing: {
-    a: '',
+		// Text after everything
+	},
+	comments2: {
+		k: '',
+		// Text after everything, but no newline above
+	},
+	spacing: {
+		a: '',
 
-    b: '',
-  },
-  noSpacing: {
-    a: '',
-    b: '',
-  },
+		b: '',
+	},
+	noSpacing: {
+		a: '',
+		b: '',
+	},
 }
modifiedcmds/jrsonnet-fmt/src/tests.rsdiffbeforeafterboth
before · cmds/jrsonnet-fmt/src/tests.rs
1use dprint_core::formatting::PrintOptions;2use indoc::indoc;34use crate::Printable;56fn reformat(input: &str) -> String {7	let (source, _) = jrsonnet_rowan_parser::parse(input);89	dprint_core::formatting::format(10		|| source.print(),11		PrintOptions {12			indent_width: 2,13			max_width: 100,14			use_tabs: false,15			new_line_text: "\n",16		},17	)18}1920macro_rules! assert_formatted {21	($input:literal, $output:literal) => {22		let formatted = reformat(indoc!($input));23		let mut expected = indoc!($output).to_owned();24		expected.push('\n');25		if formatted != expected {26			panic!(27				"bad formatting, expected\n```\n{formatted}\n```\nto be equal to\n```\n{expected}\n```",28			)29		}30	};31}3233#[test]34fn padding_stripped_for_multiline_comment() {35	assert_formatted!(36		"{37            /*38                Hello39                    World40            */41            _: null,42        }",43		"{44          /*45          Hello46              World47          */48          _: null,49        }"50	);51}5253#[test]54fn last_comment_respects_spacing_with_inline_comment_above() {55	assert_formatted!(56		"{57			a: '', // Inline5859			// Comment60        }",61		"{62		  a: '', // Inline6364		  // Comment65		}"66	);67}6869#[test]70fn complex_comments_snapshot() {71	insta::assert_display_snapshot!(reformat(indoc!(72		"{73		  comments: {74			_: '',75			//     Plain comment76			a: '',7778			#    Plain comment with empty line before79			b: '',80			/*Single-line multiline comment8182			*/83			c: '',8485			/**Single-line multiline doc comment8687			*/88			c: '',8990			/**Multiline doc91			Comment92			*/93			c: '',9495			/*9697	Multi-line9899	comment100			*/101			d: '',102103			e: '', // Inline comment104105			k: '',106107			// Text after everything108		  },109		  comments2: {110			k: '',111			// Text after everything, but no newline above112		  },113          spacing: {114            a: '',115116            b: '',117          },118          noSpacing: {119            a: '',120            b: '',121          },122        }"123	)))124}
after · cmds/jrsonnet-fmt/src/tests.rs
1use dprint_core::formatting::{PrintOptions, PrintItems};2use indoc::indoc;34use crate::Printable;56fn reformat(input: &str) -> String {7	let (source, _) = jrsonnet_rowan_parser::parse(input);89	dprint_core::formatting::format(10		|| {11			let mut out = PrintItems::new();12			source.print(&mut out);13			out14		},15		PrintOptions {16			indent_width: 2,17			max_width: 100,18			use_tabs: true,19			new_line_text: "\n",20		},21	)22}2324macro_rules! assert_formatted {25	($input:literal, $output:literal) => {26		let formatted = reformat(indoc!($input));27		let mut expected = indoc!($output).to_owned();28		expected.push('\n');29		if formatted != expected {30			panic!(31				"bad formatting, expected\n```\n{formatted}\n```\nto be equal to\n```\n{expected}\n```",32			)33		}34	};35}3637#[test]38fn padding_stripped_for_multiline_comment() {39	assert_formatted!(40		"{41            /*42                Hello43                    World44            */45            _: null,46        }",47		"{48          /*49          Hello50              World51          */52          _: null,53        }"54	);55}5657#[test]58fn last_comment_respects_spacing_with_inline_comment_above() {59	assert_formatted!(60		"{61			a: '', // Inline6263			// Comment64        }",65		"{66		  a: '', // Inline6768		  // Comment69		}"70	);71}7273#[test]74fn complex_comments_snapshot() {75	insta::assert_display_snapshot!(reformat(indoc!(76		"{77		  comments: {78			_: '',79			//     Plain comment80			a: '',8182			#    Plain comment with empty line before83			b: '',84			/*Single-line multiline comment8586			*/87			c: '',8889			/**Single-line multiline doc comment9091			*/92			c: '',9394			/**Multiline doc95			Comment96			*/97			c: '',9899			/*100101	Multi-line102103	comment104			*/105			d: '',106107			e: '', // Inline comment108109			k: '',110111			// Text after everything112		  },113		  comments2: {114			k: '',115			// Text after everything, but no newline above116		  },117          spacing: {118            a: '',119120            b: '',121          },122          noSpacing: {123            a: '',124            b: '',125          },126        }"127	)))128}
modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -87,6 +87,7 @@
 	debug: DebugOpts,
 }
 
+// TODO: Add unix_sigpipe = "sig_dfl"
 fn main() {
 	let opts: Opts = Opts::parse();
 
modifiedcrates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/stdlib/format.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs
@@ -88,13 +88,13 @@
 	}
 
 	#[test]
-	#[should_panic]
+	#[should_panic = "TruncatedFormatCode"]
 	fn parse_key_missing_start() {
 		try_parse_mapping_key("").unwrap();
 	}
 
 	#[test]
-	#[should_panic]
+	#[should_panic = "TruncatedFormatCode"]
 	fn parse_key_missing_end() {
 		try_parse_mapping_key("(   ").unwrap();
 	}
modifiedcrates/jrsonnet-rowan-parser/src/tests.rsdiffbeforeafterboth
--- a/crates/jrsonnet-rowan-parser/src/tests.rs
+++ b/crates/jrsonnet-rowan-parser/src/tests.rs
@@ -248,6 +248,7 @@
 fn eval_simple() {
 	let src = "local a = 1, b = 2; a + local c = 1; c";
 	let (node, errors) = parse(src);
+	assert!(errors.is_empty());
 
 	dbg!(node);
 }
modifiedtests/tests/common.rsdiffbeforeafterboth
--- a/tests/tests/common.rs
+++ b/tests/tests/common.rs
@@ -64,12 +64,12 @@
 		FuncVal::StaticBuiltin(b) => b
 			.params()
 			.iter()
-			.map(|p| p.name().as_str().unwrap_or(&"<unnamed>").to_string())
+			.map(|p| p.name().as_str().unwrap_or("<unnamed>").to_string())
 			.collect(),
 		FuncVal::Builtin(b) => b
 			.params()
 			.iter()
-			.map(|p| p.name().as_str().unwrap_or(&"<unnamed>").to_string())
+			.map(|p| p.name().as_str().unwrap_or("<unnamed>").to_string())
 			.collect(),
 	}
 }