<commit_before>require "./test_helper.js"
extend global, require "./test_chrome_stubs.js"
global.Settings = {postUpdateHooks: {}, get: (-> ""), set: ->}
{Commands} = require "../../background_scripts/commands.js"

context "Key mappings",
  setup ->
    @testKeySequence = (key, expectedKeyText, expectedKeyLength) ->
      keySequence = Commands.parseKeySequence key
      assert.equal expectedKeyText, keySequence.join "/"
      assert.equal expectedKeyLength, keySequence.length

  should "lowercase keys correctly", ->
    @testKeySequence "a", "a", 1
    @testKeySequence "A", "A", 1
    @testKeySequence "ab", "a/b", 2

  should "parse keys with modifiers", ->
    @testKeySequence "<c-a>", "<c-a>", 1
    @testKeySequence "<c-A>", "<c-A>", 1
    @testKeySequence "<c-a><a-b>", "<c-a>/<a-b>", 2
    @testKeySequence "<m-a>", "<m-a>", 1

  should "normalize with modifiers", ->
    # Modifiers should be in alphabetical order.
    @testKeySequence "<m-c-a-A>", "<a-c-m-A>", 1

  should "parse and normalize named keys", ->
    @testKeySequence "<space>", "<space>", 1
    @testKeySequence "<Space>", "<space>", 1
    @testKeySequence "<C-Space>", "<c-space>", 1
    @testKeySequence "<f12>", "<f12>", 1
    @testKeySequence "<F12>", "<f12>", 1

  should "handle angle brackets", ->
    @testKeySequence "<", "<", 1
    @testKeySequence ">", ">", 1

    @testKeySequence "<<", "</<", 2
    @testKeySequence ">>", ">/>", 2

    @testKeySequence "<>", "</>", 2
    @testKeySequence "<>", "</>", 2

    @testKeySequence "<<space>", "</<space>", 2
    @testKeySequence "<C->>", "<c->>", 1

context "Validate commands and options",<commit_msg>More key-sequance parser tests.<commit_after>require "./test_helper.js"
extend global, require "./test_chrome_stubs.js"
global.Settings = {postUpdateHooks: {}, get: (-> ""), set: ->}
{Commands} = require "../../background_scripts/commands.js"

context "Key mappings",
  setup ->
    @testKeySequence = (key, expectedKeyText, expectedKeyLength) ->
      keySequence = Commands.parseKeySequence key
      assert.equal expectedKeyText, keySequence.join "/"
      assert.equal expectedKeyLength, keySequence.length

  should "lowercase keys correctly", ->
    @testKeySequence "a", "a", 1
    @testKeySequence "A", "A", 1
    @testKeySequence "ab", "a/b", 2

  should "parse keys with modifiers", ->
    @testKeySequence "<c-a>", "<c-a>", 1
    @testKeySequence "<c-A>", "<c-A>", 1
    @testKeySequence "<C-A>", "<c-A>", 1
    @testKeySequence "<c-a><a-b>", "<c-a>/<a-b>", 2
    @testKeySequence "<m-a>", "<m-a>", 1

  should "normalize with modifiers", ->
    # Modifiers should be in alphabetical order.
    @testKeySequence "<m-c-a-A>", "<a-c-m-A>", 1

  should "parse and normalize named keys", ->
    @testKeySequence "<space>", "<space>", 1
    @testKeySequence "<Space>", "<space>", 1
    @testKeySequence "<C-Space>", "<c-space>", 1
    @testKeySequence "<f12>", "<f12>", 1
    @testKeySequence "<F12>", "<f12>", 1

  should "handle angle brackets", ->
    @testKeySequence "<", "<", 1
    @testKeySequence ">", ">", 1

    @testKeySequence "<<", "</<", 2
    @testKeySequence ">>", ">/>", 2

    @testKeySequence "<>", "</>", 2
    @testKeySequence "<>", "</>", 2

    @testKeySequence "<<space>", "</<space>", 2
    @testKeySequence "<C->>", "<c->>", 1

  should "negative tests", ->
    # These should not be parsed as modifiers.
    @testKeySequence "<b-a>", "</b/-/a/>", 5
    @testKeySequence "<c-@@>", "</c/-/@/@/>", 6

context "Validate commands and options",
{'fraction_non_alphanumeric': 0.21668564920273348, 'fraction_numerical': 0.017369020501138952, 'mean_word_length': 3.5387596899224807, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 104, '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': '395126', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1140, 'n_words': 296}