rodolfoghi / cpf-util-rust

CPF utils written in Rust
https://crates.io/crates/cpf_util
MIT License
7 stars 1 forks source link

should format CPF with mask #1

Closed rodolfoghi closed 4 years ago

rodolfoghi commented 4 years ago

Implement function format to pass these tests:

test('should format CPF with mask', () => {
    expect(format('')).toBe('');
    expect(format('9')).toBe('9');
    expect(format('94')).toBe('94');
    expect(format('943')).toBe('943');
    expect(format('9438')).toBe('943.8');
    expect(format('94389')).toBe('943.89');
    expect(format('943895')).toBe('943.895');
    expect(format('9438957')).toBe('943.895.7');
    expect(format('94389575')).toBe('943.895.75');
    expect(format('943895751')).toBe('943.895.751');
    expect(format('9438957510')).toBe('943.895.751-0');
    expect(format('94389575104')).toBe('943.895.751-04');
  });

P.S: The code above is written in TypeScript.

In Rust we will have something like this:

#[test]
fn should_format_cpf_empty() {
    assert_eq!(cpf::format(""), "");
}
rodolfoghi commented 4 years ago

https://github.com/brazilian-utils/brazilian-utils/blob/master/src/utilities/cpf/index.test.ts