Functional Weave
Code in Python

retail.sku-generate@1.0.0

vectors.json

2,019 bytes · view raw

[
  { "name": "prefix kept whole, each attribute cut to three characters", "args": ["TSH", ["Navy Blue", "Large", "Cotton"], 3], "expect": "TSH-NAV-LAR-COT" },
  { "name": "segment length 0 keeps attributes whole, spaces dropped", "args": ["TSH", ["Navy Blue", "XL"], 0], "expect": "TSH-NAVYBLUE-XL" },
  { "name": "an attribute shorter than the segment length is not padded", "args": ["MUG", ["Red", "M"], 4], "expect": "MUG-RED-M" },
  { "name": "lowercase and punctuation in prefix and attributes", "args": ["ab-1", ["x/l", "  50 cm "], 0], "expect": "AB1-XL-50CM" },
  { "name": "an empty prefix is left out, no leading hyphen", "args": ["", ["Blue", "S"], 3], "expect": "BLU-S" },
  { "name": "sharp s is dropped, not uppercased to SS as a naive toUpperCase first would", "args": ["", ["Straße"], 0], "expect": "STRAE" },
  { "name": "accented letters are dropped, not transliterated", "args": ["DES", ["Crème", "Brûlée"], 0], "expect": "DES-CRME-BRLE" },
  { "name": "a decimal size keeps its digits and loses the point", "args": ["SH", ["10.5", "UK"], 0], "expect": "SH-105-UK" },
  { "name": "truncation counts characters after cleaning", "args": ["P", ["N-a-v-y"], 3], "expect": "P-NAV" },
  { "name": "segment length 1 keeps initials", "args": ["SOCK", ["Black", "Wool", "Medium"], 1], "expect": "SOCK-B-W-M" },
  { "name": "the prefix is never truncated", "args": ["LONGPREFIX", ["Green"], 2], "expect": "LONGPREFIX-GR" },
  { "name": "no attributes is an error", "args": ["TSH", [], 3], "expectError": "a SKU needs at least one attribute" },
  { "name": "an attribute with no letters or digits is an error", "args": ["TSH", ["Blue", "***"], 3], "expectError": "attribute 2 (\"***\") has no letters or digits" },
  { "name": "a prefix with no letters or digits is an error", "args": ["!!!", ["Blue"], 3], "expectError": "prefix (\"!!!\") has no letters or digits" },
  { "name": "a negative segment length is an error", "args": ["TSH", ["Blue"], -1], "expectError": "segmentLength must be 0 or more" }
]