<commit_before>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library preferences_test;

import 'dart:async';

//import 'package:chrome/chrome_app.dart' as chrome;
import 'package:unittest/unittest.dart';

import '../lib/preferences.dart';
import '../lib/utils.dart';

defineTests() {
  group('editorConfig', () {
    test('glob test - general', () {
      Glob glob = new Glob("a*/b**/d?");
      expect(glob.matchPath("alpha/bravo/charlie/delta"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("alpha/bravo/charlie/d"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("alpha/bravo/charlie/do"), Glob.COMPLETE_MATCH);
      expect(glob.matchPath("abc/do"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("foo/bar"), Glob.NO_MATCH);
      expect(glob.matchPath(""), Glob.NO_MATCH);

      glob = new Glob("a*/b*");
      expect(glob.matchPath("abc/"), Glob.PREFIX_MATCH);
    });

    test('glob test - escaping', () {
      Glob glob = new Glob("a**/foo\\ bar");
      expect(glob.matchPath("aaa/bbb"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("aaa/bbb/foo ba"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("aaa/bbb/foo bar"), Glob.COMPLETE_MATCH);
      expect(glob.matchPath("aaa/bbb/foo barb"), Glob.PREFIX_MATCH);

      glob = new Glob("foo.dart");
      expect(glob.matchPath("foo.dart"), Glob.COMPLETE_MATCH);
      expect(glob.matchPath("foo!dart"), Glob.NO_MATCH);
    });
  });

  group('preferences.chrome', () {
    test('writeRead', () {
      localStore.setValue("foo1", "bar1");
      return localStore.getValue("foo1").then((String val) {
        expect(localStore.isDirty, true);
        expect(val, "bar1");
      });
    });

    test('writeReadSync', () {
      syncStore.setValue("foo2", "bar2");
      return syncStore.getValue("foo2").then((String val) {
        expect(val, "bar2");
      });
    });

    test('write fires event', () {
      Future future = localStore.onPreferenceChange.take(1).toList().then((List<PreferenceEvent> events) {
        PreferenceEvent event = events.single;
        expect(event.key, "foo1");
        expect(event.value, "bar");
      });

      localStore.setValue("foo1", "bar");

      return future;
    });
<commit_msg>Added tests for EditorConfig classes<commit_after>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library preferences_test;

import 'dart:async';

//import 'package:chrome/chrome_app.dart' as chrome;
import 'package:unittest/unittest.dart';

import '../lib/preferences.dart';
import '../lib/utils.dart';

String editorConfigContent = """

# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = false

# 4 space indentation
[*.py]
indent_style = tab
indent_size = 4

# Tab indentation (no size specified)
[[!a-g]]
tab_width = 3
indent_size = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_size = 5

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = tab
""";

defineTests() {
  group('editorConfig', () {
    test('glob test - general', () {
      Glob glob = new Glob("a*/b**/d?");
      expect(glob.matchPath("alpha/bravo/charlie/delta"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("alpha/bravo/charlie/d"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("alpha/bravo/charlie/do"), Glob.COMPLETE_MATCH);
      expect(glob.matchPath("abc/do"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("foo/bar"), Glob.NO_MATCH);
      expect(glob.matchPath(""), Glob.NO_MATCH);

      glob = new Glob("a*/b*");
      expect(glob.matchPath("abc/"), Glob.PREFIX_MATCH);
    });

    test('glob test - escaping', () {
      Glob glob = new Glob("a**/foo\\ bar");
      expect(glob.matchPath("aaa/bbb"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("aaa/bbb/foo ba"), Glob.PREFIX_MATCH);
      expect(glob.matchPath("aaa/bbb/foo bar"), Glob.COMPLETE_MATCH);
      expect(glob.matchPath("aaa/bbb/foo barb"), Glob.PREFIX_MATCH);

      glob = new Glob("foo.dart");
      expect(glob.matchPath("foo.dart"), Glob.COMPLETE_MATCH);
      expect(glob.matchPath("foo!dart"), Glob.NO_MATCH);
    });

    test('EditorConfig - parsing', () {
      EditorConfig e = new EditorConfig.fromString(editorConfigContent);

      expect(e.root, true);
      EditorConfigSection section = e.sections["*"];
      expect(section.lineEnding, EditorConfigSection.ENDING_LF);
      expect(section.insertFinalNewline, false);
      section = e.sections["*.py"];
      expect(section.useSpaces, false);
      expect(section.indentSize, 4);
      section = e.sections["lib/**.js"];
      expect(section.tabWidth, 5);
      expect(section.indentSize, 5);
      section = e.sections["lib/**.js"];
      expect(section.tabWidth, 2);
      expect(section.indentSize, 2);
    });
  });

  group('preferences.chrome', () {
    test('writeRead', () {
      localStore.setValue("foo1", "bar1");
      return localStore.getValue("foo1").then((String val) {
        expect(localStore.isDirty, true);
        expect(val, "bar1");
      });
    });

    test('writeReadSync', () {
      syncStore.setValue("foo2", "bar2");
      return syncStore.getValue("foo2").then((String val) {
        expect(val, "bar2");
      });
    });

    test('write fires event', () {
      Future future = localStore.onPreferenceChange.take(1).toList().then((List<PreferenceEvent> events) {
        PreferenceEvent event = events.single;
        expect(event.key, "foo1");
        expect(event.value, "bar");
      });

      localStore.setValue("foo1", "bar");

      return future;
    });

{'fraction_non_alphanumeric': 0.16842281317946145, 'fraction_numerical': 0.006522829904666332, 'mean_word_length': 3.4132841328413286, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3609638', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1934, 'n_words': 378}