import {describe, expect, test} from 'bun:test' import * as f from '.' // TODO : Test logging describe('email', () => { const emails: [string, boolean][] = [ ['pascal@pband.ch', true], ['p@p.ch', true], [`${'a'.repeat(64)}@${'b'.repeat(60)}.ch`, true], [`${'a'.repeat(128)}@${'b'.repeat(64)}.ch`, false], ['google.ch@test.com', true], ['pascal+truc@pband.ch', true], ['pascal+.@pband.ch', false], ['pascal+p.@pband.ch', false], ['pascal@pband.', false], ['pascal@pband', false], ['pascal@.ch', false], ['@pband.ch', false], ['prout', false], ['google.ch', false], ] for (const [email, valid] of emails) { test(`"${email}" is ${valid ? 'valid' : 'invalid'}`, () => { const res = expect(f.email_is_valid(email)) if (valid) { res.toBeTrue() } else { res.toBeFalse() } }) } }) describe('Password strength', () => { // TODO : More passwords lol const pwds: [string, f.PasswordStrength][] = [ // ['test', f.PasswordStrength.Strong], ['OkPassword', f.PasswordStrength.Easy], ] for (const pwd of pwds) { for (const level of [f.PasswordStrength.Weak, f.PasswordStrength.Easy, f.PasswordStrength.Medium, f.PasswordStrength.Strong, f.PasswordStrength.Hard]) { const should_pass = level <= pwd[1] test(`"${pwd[0]}" should ${should_pass ? '' : 'not '}pass level ${level}`, () => { const res = expect(f.password_is_strong(pwd[0], level as f.PasswordStrength)) if (should_pass) { res.toBeTrue() } else { res.toBeFalse() } }) } } }) describe('Contains HTML', () => { const texts: [string, boolean][] = [ ['Hello, world!', false], ['