{"record":{"id":"0344823f656a2ad2","repo":"Humanizr/Humanizer","slug":"test-input-must-define-durationcases","errorCode":null,"errorMessage":"Test input must define durationCases.","messagePattern":"Test input must define durationCases\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Humanizer.SourceGenerators/Common/DurationCaseModels.cs","lineNumber":403,"sourceCode":"                localeCode,\n                classification,\n                \"nominative\",\n                [\"nominative\", .. cases.Keys.OrderBy(static name => name, StringComparer.Ordinal)],\n                EmptyRealizations(),\n                EmptySources(),\n                cases.ToImmutable().Add(\"nominative\", CreateBaseDurationOverlay()));\n        }\n\n        internal static DurationCaseCatalog ParseForTests(\n            string localeCode,\n            string text,\n            string? casePluralRule = null,\n            string? phrasesText = null)\n        {\n            var root = SimpleYamlParser.Parse($\"durationCases:\\n{text}\");\n            if (!root.TryGetValue(\"durationCases\", out var value))\n            {\n                throw new InvalidOperationException(\"Test input must define durationCases.\");\n            }\n\n            SimpleYamlValue? phrases = null;\n            if (phrasesText is not null)\n            {\n                var phrasesRoot = SimpleYamlParser.Parse($\"phrases:\\n{phrasesText}\");\n                _ = phrasesRoot.TryGetValue(\"phrases\", out phrases);\n            }\n\n            var path = $\"{localeCode}.durationCases\";\n            var mapping = ExpectMapping(value, path);\n            return mapping.TryGetValue(\"inventory\", out _) ||\n                   mapping.TryGetValue(\"sources\", out _) ||\n                   mapping.TryGetValue(\"provenance\", out _) ||\n                   mapping.TryGetValue(\"reason\", out _)\n                ? Parse(localeCode, value, casePluralRule, phrases)\n                : ParseLegacyForTests(localeCode, mapping, path);\n        }","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer.SourceGenerators/Common/DurationCaseModels.cs#L385-L421","documentation":"Thrown by ParseForTests when the provided test YAML text, after being wrapped and parsed, does not contain a 'durationCases' key at the root. ParseForTests prepends 'durationCases:\\n' to the input, so this fires only if the SimpleYamlParser fails to find the key after wrapping — indicating the input text was malformed or empty.","triggerScenarios":"ParseForTests does SimpleYamlParser.Parse('durationCases:\\n' + text) and then TryGetValue('durationCases'). If the parser produces a root without the key (e.g. the input text overrode it or was empty whitespace), the throw fires. For example, passing an empty string or a string that starts with a top-level key.","commonSituations":"A test passes string.Empty or whitespace as the durationCases text. Or the test text starts with its own 'durationCases:' key, causing a duplicate that the parser collapses unexpectedly. The helper expects raw block content (indented YAML), not a full document.","solutions":["Pass only the indented block content (what goes under durationCases:), not the full document. E.g. pass '  classification: distinct\\n  cases:\\n    ...' not 'durationCases:\\n  classification: distinct'.","Ensure the text is non-empty and contains valid YAML block syntax.","If testing with no duration data is intentional, use a different test helper or skip the ParseForTests call."],"exampleFix":"// before (passing full document)\nvar catalog = DurationCaseNormalization.ParseForTests(\"xx\",\n    \"durationCases:\\n  classification: distinct\");\n// after (passing block content only)\nvar catalog = DurationCaseNormalization.ParseForTests(\"xx\",\n    \"classification: distinct\\n  cases:\\n    genitive: { ... }\");","handlingStrategy":"validation","validationCode":"// Verify test input will produce a durationCases root after wrapping\nstatic bool TestInputIsValid(string text)\n{\n    if (string.IsNullOrWhiteSpace(text)) return false;\n    // Ensure the text doesn't itself declare durationCases at column 0\n    return !text.Split('\\n', StringSplitOptions.RemoveEmptyEntries)\n        .Any(line => line.TrimStart().StartsWith(\"durationCases:\", StringComparison.Ordinal));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass block content to ParseForTests (indented YAML), not a full document with the durationCases header.","Never pass empty or whitespace-only strings to ParseForTests.","Check existing ParseForTests call sites for the expected input shape."],"tags":["source-generator","duration-cases","testing","test-helper"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}