string-le 0.2.2

Extract every string in a codebase, with its position, so a person can read them
[
	{
		"name": "a json document",
		"file": "strings.json",
		"arguments": {
			"format": "json"
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"Welcome Home",
					"https://example.com/path?query=1",
					"usr_8f3k2j4h5g6",
					"line one\nline two",
					"trimmed value",
					"Nested message",
					"first item",
					"second item"
				],
				"fileType": "json"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 8,
				"truncated": false
			}
		}
	},
	{
		"name": "format inferred from the filename",
		"file": "strings.toml",
		"arguments": {
			"filename": "strings.toml"
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"TOML Example",
					"literal string",
					"Tom Preston-Werner",
					"Multi-line\nbasic string",
					"alpha",
					"beta",
					"value with # hash"
				],
				"fileType": "toml"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 7,
				"truncated": false
			}
		}
	},
	{
		"name": "an alias resolves",
		"file": "strings.yaml",
		"arguments": {
			"format": "yml"
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"Unquoted plain scalar",
					"Double quoted value",
					"Single quoted value",
					"plain item",
					"quoted item",
					"Block scalar line one\nBlock scalar line two",
					"Folded scalar text",
					"inline quoted",
					"bare"
				],
				"fileType": "yaml"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 9,
				"truncated": false
			}
		}
	},
	{
		"name": "a dotenv document",
		"file": "strings.env",
		"arguments": {
			"format": "env"
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"https://api.example.com",
					"quoted value",
					"single value",
					"value",
					"value # not a comment",
					"padded value",
					"12345"
				],
				"fileType": "env"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 7,
				"truncated": false
			}
		}
	},
	{
		"name": "a python document, docstring included",
		"file": "strings.py",
		"arguments": {
			"format": "python"
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"Module docstring.\n\nTwo lines, one string.",
					"the docs",
					"Greet a user politely.",
					"Hello, {name}!",
					"\\d+ items",
					"bytes",
					"raw bytes",
					"single quoted",
					"a # inside a string"
				],
				"fileType": "python"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 9,
				"truncated": false
			}
		}
	},
	{
		"name": "a rust raw string is one value",
		"file": "strings.rs",
		"arguments": {
			"filename": "strings.rs"
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"the docs",
					"a raw \"quoted\" string",
					"holds a \"# sequence",
					"C:\\Users\\test",
					"payload",
					"say \\\"hi\\\"",
					"first\nsecond"
				],
				"fileType": "rust"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 7,
				"truncated": false
			}
		}
	},
	{
		"name": "a shell heredoc is one value",
		"file": "strings.sh",
		"arguments": {
			"format": "sh"
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"the docs",
					"The heredoc body.\nSecond line.",
					"No $expansion here.",
					"tab indented body",
					"double quoted",
					"single quoted",
					"$file"
				],
				"fileType": "shellscript"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 7,
				"truncated": false
			}
		}
	},
	{
		"name": "an unknown format falls back rather than failing",
		"file": "messages.ts",
		"arguments": {
			"format": "klingon"
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"Delete this permanently?",
					"This can't be undone",
					"Removing ${count} items",
					"It\\'s fine",
					"quoted text"
				],
				"fileType": "fallback"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 5,
				"truncated": false
			}
		}
	},
	{
		"name": "no format at all falls back",
		"file": "messages.ts",
		"arguments": {},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"Delete this permanently?",
					"This can't be undone",
					"Removing ${count} items",
					"It\\'s fine",
					"quoted text"
				],
				"fileType": "fallback"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 5,
				"truncated": false
			}
		}
	},
	{
		"name": "deduped",
		"file": "escapes.json",
		"arguments": {
			"format": "json",
			"dedupe": true
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"readable",
					"first\nsecond",
					"she said \"hi\"",
					"café"
				],
				"fileType": "json"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 4,
				"truncated": false
			}
		}
	},
	{
		"name": "capped and flagged",
		"file": "strings.csv",
		"arguments": {
			"format": "csv",
			"maxResults": 3
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [
					"name",
					"message",
					"count"
				],
				"fileType": "csv"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 3,
				"truncated": true
			}
		}
	},
	{
		"name": "nothing to find",
		"content": "",
		"arguments": {
			"format": "json"
		},
		"expected": {
			"ok": true,
			"data": {
				"strings": [],
				"fileType": "json"
			},
			"diagnostics": [],
			"meta": {
				"tool": "extract_strings",
				"count": 0,
				"truncated": false
			}
		}
	},
	{
		"name": "content must be a string",
		"arguments": {
			"format": "json"
		},
		"expectedError": "content is required and must be a string"
	},
	{
		"name": "a nonsensical cap is rejected",
		"content": "x",
		"arguments": {
			"maxResults": 0
		},
		"expectedError": "maxResults must be a positive integer"
	}
]