{
  "$schema": "../cases.schema.json",
  "format": 1,
  "domain": "suframa",
  "title": {
    "en": "SUFRAMA registration",
    "pt-BR": "Inscrição SUFRAMA"
  },
  "functions": [
    {
      "id": "suframa.format",
      "level": "extended",
      "summary": "Formats an Inscrição SUFRAMA as `SS.NNNN.LLD`.",
      "description": "Formats an Inscrição SUFRAMA with the mask `00.0000.000`. Only the structure changes (use `suframa.isValid` to check the number).\n\n- The mask is progressive: a partial value is masked as far as it goes. Characters that are not digits are dropped, and digits after the 9th are ignored.\n- `options.pad` first left-pads the value with zeros to 9 digits. A value with no digits (empty, or only letters and symbols) gives an empty string, even with `pad`.\n- An 8-digit value is a number whose sector lost its leading zero. Without `pad`, the mask groups it one position early (`10001018` gives `10.0010.18`). Use `{ pad: true }` to get the correct mask (`01.0001.018`).\n- A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number returns an empty string.",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        },
        {
          "name": "options",
          "type": "FormatSuframaOptions",
          "optional": true
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "suframa.format#[\"123456789\"]",
          "args": [
            "123456789"
          ],
          "expect": {
            "returns": "12.3456.789"
          },
          "note": "from the maintainer briefing, #559"
        },
        {
          "id": "suframa.format#[\"10001018\"]",
          "args": [
            "10001018"
          ],
          "expect": {
            "returns": "10.0010.18"
          },
          "note": "from the maintainer briefing, #559"
        },
        {
          "id": "suframa.format#[\"10001018\",{\"pad\":true}]",
          "args": [
            "10001018",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "01.0001.018"
          },
          "note": "from the maintainer briefing, #559"
        },
        {
          "id": "suframa.format#[-101234567]",
          "args": [
            -101234567
          ],
          "expect": {
            "returns": ""
          },
          "note": "from the maintainer briefing, #559"
        },
        {
          "id": "suframa.format#[\"\"]",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a no formatted string"
        },
        {
          "id": "suframa.format#[\"2\"]",
          "args": [
            "2"
          ],
          "expect": {
            "returns": "2"
          },
          "note": "JavaScript's own test: when it is a no formatted string"
        },
        {
          "id": "suframa.format#[\"205\"]",
          "args": [
            "205"
          ],
          "expect": {
            "returns": "20.5"
          },
          "note": "JavaScript's own test: when it is a no formatted string"
        },
        {
          "id": "suframa.format#[\"205678\"]",
          "args": [
            "205678"
          ],
          "expect": {
            "returns": "20.5678"
          },
          "note": "JavaScript's own test: when it is a no formatted string"
        },
        {
          "id": "suframa.format#[\"2056781\"]",
          "args": [
            "2056781"
          ],
          "expect": {
            "returns": "20.5678.1"
          },
          "note": "JavaScript's own test: when it is a no formatted string"
        },
        {
          "id": "suframa.format#[\"205678106\"]",
          "args": [
            "205678106"
          ],
          "expect": {
            "returns": "20.5678.106"
          },
          "note": "JavaScript's own test: when it is a no formatted string"
        },
        {
          "id": "suframa.format#[\"20.5678.10-6\"]",
          "args": [
            "20.5678.10-6"
          ],
          "expect": {
            "returns": "20.5678.106"
          },
          "note": "JavaScript's own test: when it is a formatted string"
        },
        {
          "id": "suframa.format#[\"20#Error*&@#5678#Char!106\"]",
          "args": [
            "20#Error*&@#5678#Char!106"
          ],
          "expect": {
            "returns": "20.5678.106"
          },
          "note": "JavaScript's own test: when it is a malformed string"
        },
        {
          "id": "suframa.format#[205]",
          "args": [
            205
          ],
          "expect": {
            "returns": "20.5"
          },
          "note": "JavaScript's own test: when it is a number"
        },
        {
          "id": "suframa.format#[205678106]",
          "args": [
            205678106
          ],
          "expect": {
            "returns": "20.5678.106"
          },
          "note": "JavaScript's own test: when it is a number"
        },
        {
          "id": "suframa.format#[10001018]",
          "args": [
            10001018
          ],
          "expect": {
            "returns": "10.0010.18"
          },
          "note": "JavaScript's own test: when it is a number"
        },
        {
          "id": "suframa.format#[10001018,{\"pad\":true}]",
          "args": [
            10001018,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "01.0001.018"
          },
          "note": "JavaScript's own test: should left pad with zeros when the pad option is set"
        },
        {
          "id": "suframa.format#[\"1\",{\"pad\":true}]",
          "args": [
            "1",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "00.0000.001"
          },
          "note": "JavaScript's own test: should left pad with zeros when the pad option is set"
        },
        {
          "id": "suframa.format#[\"205678106\",{\"pad\":true}]",
          "args": [
            "205678106",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": "20.5678.106"
          },
          "note": "JavaScript's own test: should left pad with zeros when the pad option is set"
        },
        {
          "id": "suframa.format#[\"10001018\",{\"pad\":false}]",
          "args": [
            "10001018",
            {
              "pad": false
            }
          ],
          "expect": {
            "returns": "10.0010.18"
          },
          "note": "JavaScript's own test: should not pad when the pad option is false"
        },
        {
          "id": "suframa.format#[\"205678106999\"]",
          "args": [
            "205678106999"
          ],
          "expect": {
            "returns": "20.5678.106"
          },
          "note": "JavaScript's own test: should NOT add digits after the Inscrição SUFRAMA length (9)"
        },
        {
          "id": "suframa.format#[-1]",
          "args": [
            -1
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number"
        },
        {
          "id": "suframa.format#[1.5]",
          "args": [
            1.5
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number"
        },
        {
          "id": "suframa.format#[9007199254740992]",
          "args": [
            9007199254740992
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number"
        },
        {
          "id": "suframa.format#[-101234567,{\"pad\":true}]",
          "args": [
            -101234567,
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number"
        },
        {
          "id": "suframa.format#[\"\",{\"pad\":true}]",
          "args": [
            "",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "a value with no digits gives an empty string even with pad. JavaScript's own test: should return an empty string for a value without digits"
        },
        {
          "id": "suframa.format#[\"abc\",{\"pad\":true}]",
          "args": [
            "abc",
            {
              "pad": true
            }
          ],
          "expect": {
            "returns": ""
          },
          "note": "a value with letters only has no digits"
        }
      ]
    },
    {
      "id": "suframa.generate",
      "level": "extended",
      "summary": "Generates a random Inscrição SUFRAMA with a valid check digit.",
      "description": "Generates a random Inscrição SUFRAMA with a valid check digit: always 9 digits, unformatted.\n\n- The sector is never `00`, the only structural rule the NF-e manual states.\n- Sector and locality are random. They need not match codes SUFRAMA uses.",
      "params": [],
      "returns": "string",
      "cases": [
        {
          "id": "suframa.generate#generated-is-valid",
          "args": [],
          "expect": {
            "satisfies": "suframa.isValid"
          },
          "repeat": 5,
          "note": "every generated value must pass the lib's own validator"
        },
        {
          "id": "suframa.generate#nine-digits-never-sector-00",
          "args": [],
          "expect": {
            "matches": "^(0[1-9]|[1-9][0-9])[0-9]{7}$"
          },
          "repeat": 10,
          "note": "JavaScript's own test: should generate 9 digit numbers its own validator accepts, never with sector code 00"
        }
      ]
    },
    {
      "id": "suframa.isValid",
      "level": "extended",
      "summary": "Checks whether an Inscrição SUFRAMA is valid.",
      "description": "Validates an Inscrição SUFRAMA: the layout `SS.NNNN.LLD` (sector, sequential number, locality of the SUFRAMA unit and check digit) and its modulus 11 check digit.\n\n- The NF-e field is numeric, with 8 or 9 positions. The sector `SS` can start with 0, and the number then loses that zero and has 8 digits. The sector can never be `00`.\n- An 8-digit value is validated with the zero put back on the left. So an 8-digit value that starts with 0 is rejected, because it becomes sector `00`. The NF-e manual only says that `SS` can start with 0: this reading of 8 digits is an inference of the library.\n- Check digit: modulus 11 over the first 8 digits, weights 2 to 9 from right to left. The digit is 0 when the remainder is 0 or 1.\n- Accepts the mask characters whitespace, `.`, `-` and `/`, alone or in a run, between the fields of `SS.NNNN.LLD` (the check digit included, as in `20.5678.10-6`), and surrounding whitespace. Any other character, or a separator inside a field, makes the value invalid.\n- Sector and locality are not checked against a table: there is no complete official list. For that reason there is no `getSuframaInfo`.\n- Rule E18-30 of the NF-e (recipient in AC, AM, RO, RR or Macapá/Santana-AP) is out of scope.\n- The rule comes from the NF-e Manual de Orientação do Contribuinte (MOC 7.0, section 8.4, and field E18 `ISUF`, rule E18-20, rejection 235). SUFRAMA itself publishes no layout and no check digit.\n- Only a string is read. Any other type returns `false`.",
      "params": [
        {
          "name": "suframa",
          "type": "string"
        }
      ],
      "returns": "boolean",
      "cases": [
        {
          "id": "suframa.isValid#[\"123456789\"]",
          "args": [
            "123456789"
          ],
          "expect": {
            "returns": true
          },
          "note": "from the maintainer briefing, #559 (the example of the NF-e manual)"
        },
        {
          "id": "suframa.isValid#[\"12.3456.789\"]",
          "args": [
            "12.3456.789"
          ],
          "expect": {
            "returns": true
          },
          "note": "from the maintainer briefing, #559"
        },
        {
          "id": "suframa.isValid#[\"10001018\"]",
          "args": [
            "10001018"
          ],
          "expect": {
            "returns": true
          },
          "note": "from the maintainer briefing, #559 (8 digits, same as 010001018)"
        },
        {
          "id": "suframa.isValid#[\"001234560\"]",
          "args": [
            "001234560"
          ],
          "expect": {
            "returns": false
          },
          "note": "from the maintainer briefing, #559 (sector 00)"
        },
        {
          "id": "suframa.isValid#[\"\"]",
          "args": [
            ""
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when it is an empty string"
        },
        {
          "id": "suframa.isValid#whitespace-only",
          "args": [
            "   "
          ],
          "expect": {
            "returns": false
          }
        },
        {
          "id": "suframa.isValid#[\"1234567\"]",
          "args": [
            "1234567"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when it has fewer than 8 digits"
        },
        {
          "id": "suframa.isValid#[\"0001018\"]",
          "args": [
            "0001018"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when it has fewer than 8 digits"
        },
        {
          "id": "suframa.isValid#[\"1234567899\"]",
          "args": [
            "1234567899"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when it has more than 9 digits, even if the first 9 are valid"
        },
        {
          "id": "suframa.isValid#[\"1234567090\"]",
          "args": [
            "1234567090"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when it has more than 9 digits, even if the last 9 are valid"
        },
        {
          "id": "suframa.isValid#[\"12345678A9\"]",
          "args": [
            "12345678A9"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when it contains letters or special characters"
        },
        {
          "id": "suframa.isValid#[\"12#3456#789\"]",
          "args": [
            "12#3456#789"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when it contains letters or special characters"
        },
        {
          "id": "suframa.isValid#[\"abcdefghi\"]",
          "args": [
            "abcdefghi"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when it contains letters or special characters"
        },
        {
          "id": "suframa.isValid#[\"123456780\"]",
          "args": [
            "123456780"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when the check digit is wrong"
        },
        {
          "id": "suframa.isValid#[\"205678105\"]",
          "args": [
            "205678105"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when the check digit is wrong"
        },
        {
          "id": "suframa.isValid#[\"10001019\"]",
          "args": [
            "10001019"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when the check digit is wrong"
        },
        {
          "id": "suframa.isValid#[\"100000011\"]",
          "args": [
            "100000011"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when the remainder is 0 or 1 and the check digit is not 0"
        },
        {
          "id": "suframa.isValid#[\"600001301\"]",
          "args": [
            "600001301"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when the remainder is 0 or 1 and the check digit is not 0"
        },
        {
          "id": "suframa.isValid#[\"000000000\"]",
          "args": [
            "000000000"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when the sector code is 00"
        },
        {
          "id": "suframa.isValid#[\"000000019\"]",
          "args": [
            "000000019"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when the sector code is 00"
        },
        {
          "id": "suframa.isValid#[\"01234560\"]",
          "args": [
            "01234560"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when an 8 digit value starts with 0, which reads as sector code 00"
        },
        {
          "id": "suframa.isValid#[\"010001018\"]",
          "args": [
            "010001018"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when it is a valid Inscrição SUFRAMA without mask"
        },
        {
          "id": "suframa.isValid#[\"101234015\"]",
          "args": [
            "101234015"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when it is a valid Inscrição SUFRAMA without mask"
        },
        {
          "id": "suframa.isValid#[\"205678106\"]",
          "args": [
            "205678106"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when it is a valid Inscrição SUFRAMA without mask"
        },
        {
          "id": "suframa.isValid#[\"601234308\"]",
          "args": [
            "601234308"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when it is a valid Inscrição SUFRAMA without mask"
        },
        {
          "id": "suframa.isValid#[\"20.5678.10-6\"]",
          "args": [
            "20.5678.10-6"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when it is a valid Inscrição SUFRAMA with mask"
        },
        {
          "id": "suframa.isValid#[\"20 5678 10 6\"]",
          "args": [
            "20 5678 10 6"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when it is a valid Inscrição SUFRAMA with mask"
        },
        {
          "id": "suframa.isValid#[\"1.0001.018\"]",
          "args": [
            "1.0001.018"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when it has 8 digits because the sector code lost its leading zero"
        },
        {
          "id": "suframa.isValid#[\"100000010\"]",
          "args": [
            "100000010"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when the remainder is 0 and the check digit is 0"
        },
        {
          "id": "suframa.isValid#[\"600001300\"]",
          "args": [
            "600001300"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when the remainder is 1 and the check digit is 0"
        },
        {
          "id": "suframa.isValid#[\"100000061\"]",
          "args": [
            "100000061"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when the remainder is 10 and the check digit is 1"
        },
        {
          "id": "suframa.isValid#[\"(12)3456789\"]",
          "args": [
            "(12)3456789"
          ],
          "expect": {
            "returns": false
          },
          "note": "parentheses are not mask characters. JavaScript's own test: when it contains letters or special characters"
        },
        {
          "id": "suframa.isValid#[\"12,3456,789\"]",
          "args": [
            "12,3456,789"
          ],
          "expect": {
            "returns": false
          },
          "note": "the comma is not a mask character. JavaScript's own test: when it contains letters or special characters"
        },
        {
          "id": "suframa.isValid#[\"12*3456*789\"]",
          "args": [
            "12*3456*789"
          ],
          "expect": {
            "returns": false
          },
          "note": "the asterisk is not a mask character. JavaScript's own test: when it contains letters or special characters"
        },
        {
          "id": "suframa.isValid#[\"1.23456789\"]",
          "args": [
            "1.23456789"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when a separator sits inside a field or before or after the value"
        },
        {
          "id": "suframa.isValid#[\"123.456.789\"]",
          "args": [
            "123.456.789"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when a separator sits inside a field or before or after the value"
        },
        {
          "id": "suframa.isValid#[\"-123456789\"]",
          "args": [
            "-123456789"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when a separator sits inside a field or before or after the value"
        },
        {
          "id": "suframa.isValid#[\"123456789.\"]",
          "args": [
            "123456789."
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when a separator sits inside a field or before or after the value"
        },
        {
          "id": "suframa.isValid#[\"123456788\"]",
          "args": [
            "123456788"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when the check digit is wrong"
        },
        {
          "id": "suframa.isValid#[\" 20--5678//10 6 \"]",
          "args": [
            " 20--5678//10 6 "
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: when it is a valid Inscrição SUFRAMA with mask (a run of separators and surrounding whitespace)"
        },
        {
          "id": "suframa.isValid#[123456789]",
          "args": [
            123456789
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: when it is a non-string that stringifies to a valid Inscrição SUFRAMA"
        }
      ]
    },
    {
      "id": "suframa.parse",
      "level": "extended",
      "summary": "Removes the formatting characters of an Inscrição SUFRAMA and returns only the digits.",
      "description": "Removes Inscrição SUFRAMA formatting and keeps only digits, capped at 9, the way the `ISUF` field of the NF-e expects them.\n\n- The function does not left-pad the value. An 8-digit value stays with 8 digits.\n- A number is read only when it is a safe non-negative integer. A negative, fractional, non-finite or unsafe number returns an empty string.",
      "params": [
        {
          "name": "value",
          "type": "string | number"
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "suframa.parse#[\"12.3456.789\"]",
          "args": [
            "12.3456.789"
          ],
          "expect": {
            "returns": "123456789"
          },
          "note": "JavaScript's own test: should remove Inscrição SUFRAMA mask characters"
        },
        {
          "id": "suframa.parse#[\"20.5678.10-6\"]",
          "args": [
            "20.5678.10-6"
          ],
          "expect": {
            "returns": "205678106"
          },
          "note": "JavaScript's own test: should remove Inscrição SUFRAMA mask characters"
        },
        {
          "id": "suframa.parse#[\"123456789\"]",
          "args": [
            "123456789"
          ],
          "expect": {
            "returns": "123456789"
          },
          "note": "JavaScript's own test: should keep an unmasked value as it is"
        },
        {
          "id": "suframa.parse#[\"10001018\"]",
          "args": [
            "10001018"
          ],
          "expect": {
            "returns": "10001018"
          },
          "note": "JavaScript's own test: should keep an unmasked value as it is"
        },
        {
          "id": "suframa.parse#[123456789]",
          "args": [
            123456789
          ],
          "expect": {
            "returns": "123456789"
          },
          "note": "JavaScript's own test: should accept a number"
        },
        {
          "id": "suframa.parse#[\"12#Error*&@#3456#Char!789\"]",
          "args": [
            "12#Error*&@#3456#Char!789"
          ],
          "expect": {
            "returns": "123456789"
          },
          "note": "JavaScript's own test: should remove non numeric characters"
        },
        {
          "id": "suframa.parse#[\"123456789123\"]",
          "args": [
            "123456789123"
          ],
          "expect": {
            "returns": "123456789"
          },
          "note": "JavaScript's own test: should ignore digits after the Inscrição SUFRAMA length"
        },
        {
          "id": "suframa.parse#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          }
        },
        {
          "id": "suframa.parse#[10123456.7]",
          "args": [
            10123456.7
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number"
        },
        {
          "id": "suframa.parse#[-1]",
          "args": [
            -1
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number"
        },
        {
          "id": "suframa.parse#[9007199254740992]",
          "args": [
            9007199254740992
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: when it is a negative, fractional or unsafe number"
        }
      ]
    }
  ]
}
