git.delta.rocks / jrsonnet / refs/commits / 9b1cb43cbd7b

difftreelog

source

crates/jrsonnet-formatter/src/tests.rs1.8 KiBsourcehistory
1use dprint_core::formatting::{PrintItems, 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		|| {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}2324#[test]25fn complex_comments() {26	insta::assert_snapshot!(reformat(indoc!(27		"{28		  comments: {29			_: '',30			//     Plain comment31			a: '',3233			#    Plain comment with empty line before34			b: '',35			/*Single-line multiline comment3637			*/38			c: '',3940			/**Single-line multiline doc comment4142			*/43			c: '',4445			/**Multiline doc46			Comment47			*/48			c: '',4950			/*5152	Multi-line5354	comment55			*/56			d: '',5758			e: '', // Inline comment5960			k: '',6162			// Text after everything63		  },64		  comments2: {65			k: '',66			// Text after everything, but no newline above67		  },68          spacing: {69            a: '',7071            b: '',72          },73          noSpacing: {74            a: '',75            b: '',76          },77        }"78	)));79}8081#[test]82fn args() {83	insta::assert_snapshot!(reformat(indoc!(84		"85			{86				short: aaa(1,2,3,4,5),87				long: bbb(123123123123123123123,12312312321123123123,123123123123312123123,123123123123123123312,123123123123312321123),88				short_in_long: bbb(aaa(1,2,3,4,5), 123123123123123123123,12312312321123123123,123123123123312123123,123123123123123123312,123123123123312321123),89				long_in_short: aaa(1,2,3,4,5,bbb(123123123123123123123,12312312321123123123,123123123123312123123,123123123123123123312,123123123123312321123)),90			}91		"92	)));93}9495#[test]96fn asserts() {97	insta::assert_snapshot!(reformat(indoc!(98		"99			{100				assert 1 > 0 : 'one should be greater than zero',101				assert true,102				value: 42,103			}104		"105	)));106}