From 32c7a5e0469e220b716188d4cc16aff7f143a7d1 Mon Sep 17 00:00:00 2001 From: phaer Date: Wed, 22 Apr 2026 11:49:31 +0200 Subject: [PATCH] pkgs-lib/formats: add regression tests for toml generator Add two shouldPass tests that catch known yj regressions: - tomlHeterogeneousArray: arrays mixing scalars and attrsets crash yj with 'unexpected primitive type' (NixOS/nixpkgs#511970) - tomlCommaInKey: keys containing commas are silently truncated because yj stores TOML keys in Go struct tags where commas are option separators (sclevine/yj#52) Expected values are taken from go-toml's jsontoml output. Both tests fail under the current yj backend. --- pkgs/pkgs-lib/tests/formats.nix | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkgs/pkgs-lib/tests/formats.nix b/pkgs/pkgs-lib/tests/formats.nix index d51b5d2f272b..40c096bd88f7 100644 --- a/pkgs/pkgs-lib/tests/formats.nix +++ b/pkgs/pkgs-lib/tests/formats.nix @@ -708,6 +708,41 @@ runBuildTests { ''; }; + # Regression test for https://github.com/NixOS/nixpkgs/issues/511970 + # yj crashes on arrays mixing scalars and attrsets (heterogeneous arrays), + # e.g. Helix language-server configs like ["bash-ls", {name = "ts-ls"; ...}]. + # TOML 1.0 allows mixed-type arrays; the converter must emit them as + # inline arrays with inline tables. + tomlHeterogeneousArray = shouldPass { + format = formats.toml { }; + input = { + language-server = [ + "bash-language-server" + { + name = "typescript-language-server"; + except-features = [ "diagnostics" ]; + } + ]; + }; + expected = '' + language-server = ['bash-language-server', {except-features = ['diagnostics'], name = 'typescript-language-server'}] + ''; + }; + + # Regression test for https://github.com/sclevine/yj/issues/52 + # yj truncates keys at the first comma because it stores TOML keys in Go + # struct tags, where commas are option separators. + # e.g. "stack(x,n)" is emitted as "stack(x" — silently losing data. + tomlCommaInKey = shouldPass { + format = formats.toml { }; + input = { + "stack(x,n)" = "foobar"; + }; + expected = '' + 'stack(x,n)' = 'foobar' + ''; + }; + cdnAtoms = shouldPass { format = formats.cdn { }; input = {