<commit_before>library sanitizer_dart;

import 'package:validator/validator.dart' as s;


void test(Map options) {
  List args = options['args'];

  options['expect'].keys.forEach((input) {
    args.insert(0, input);

    var f = options["sanitizer"].toString();
    var result = Function.apply(options['sanitizer'], args);
    var expected = options['expect'][input];

    if (result != expected) {
      throw new Exception('sanitizer.$f($args) failed but should have passed');
    }
    args.removeAt(0);
  });
}


void testToString() {
  test({
    'sanitizer': s.toString,
    'args': [],
    'expect': {
      1: '1',
      1.5: '1.5',
      {1: 2}: '{1: 2}',
      null: ''
    }
  });
}


void testToDate() {
  test({
    'sanitizer': s.toDate,
    'args': [],
    'expect': {
      '2012-02-27 13:27:00': DateTime.parse('2012-02-27 13:27:00'),
      'abc': null
    }
  });
}


void main() {
  testToString();
  testToDate();

  print('-------------------------------------');
  print('All tests in sanitizer.dart complete.');
  print('-------------------------------------');
}<commit_msg>add tests, add handling of NaN comparison<commit_after>library sanitizer_dart;

import 'package:validator/validator.dart' as s;


void test(Map options) {
  List args = options['args'];

  options['expect'].keys.forEach((input) {
    args.insert(0, input);

    var f = options["sanitizer"].toString();
    var result = Function.apply(options['sanitizer'], args);
    var expected = options['expect'][input];

    if ((expected is double || expected is int) && expected.isNaN == true && result.isNaN == true) {
      return true;
    }

    if (result != expected) {
      throw new Exception('sanitizer.$f($args) failed but should have passed');
    }
    args.removeAt(0);
  });
}


void testToString() {
  test({
    'sanitizer': s.toString,
    'args': [],
    'expect': {
      1: '1',
      1.5: '1.5',
      {1: 2}: '{1: 2}',
      null: ''
    }
  });
}


void testToDate() {
  test({
    'sanitizer': s.toDate,
    'args': [],
    'expect': {
      '2012-02-27 13:27:00': DateTime.parse('2012-02-27 13:27:00'),
      'abc': null
    }
  });
}


void testToFloat() {
  test({
    'sanitizer': s.toFloat,
    'args': [],
    'expect': {
      '1': 1.0,
      '2.': 2.0,
      '-1.4': -1.4,
      'foo': double.NAN
    }
  });
}


void main() {
  testToString();
  testToDate();
  testToFloat();

  print('-------------------------------------');
  print('All tests in sanitizer.dart complete.');
  print('-------------------------------------');
}
{'fraction_non_alphanumeric': 0.2463768115942029, 'fraction_numerical': 0.03525264394829612, 'mean_word_length': 2.220680958385876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2817332', 'n_tokens_mistral': 919, 'n_tokens_neox': 862, 'n_words': 189}