<commit_before>assert = require("assert")

helpers = require("./helpers")
test = helpers.test

matchers = require("../src/service/matchers")

PathMatcher = matchers.Path

test "Path matching", ->
  matcher = new PathMatcher("/accounts/:account_id")
  assert.deepEqual(
    matcher.pattern,
    ["accounts", {name: "account_id"}]
  )
  result = matcher.match("/accounts/54321",)
  assert.deepEqual(
    result,
    {account_id: "54321"}
  )
  assert.equal(
    matcher.match("/bogus/12345"),
    false
  )
  assert.equal(
    matcher.match("/accounts/12345/channels"),
    false
  )

  matcher = new PathMatcher("/accounts/:account_id/channels")
  assert.deepEqual(
    matcher.pattern,
    ["accounts", {name: "account_id"}, "channels"]
  )

  matcher = new PathMatcher("/accounts/:account_id/channels/:channel_id")
  assert.deepEqual(
    matcher.pattern,
    ["accounts", {name: "account_id"}, "channels", {name: "channel_id"}]
  )
  assert.deepEqual(
    matcher.match("/accounts/54321/channels/abcdefg"),
    {account_id: "54321", channel_id: "abcdefg"}
  )

<commit_msg>test matching / as path<commit_after>assert = require("assert")

helpers = require("./helpers")
test = helpers.test

matchers = require("../src/service/matchers")

PathMatcher = matchers.Path

test "Path matching for '/'", ->
  matcher = new PathMatcher("/")
  assert.deepEqual(
    matcher.match("/"),
    {}
  )
  assert.equal(
    matcher.match("/foo"),
    false
  )

test "Path matching, capturing last component", ->
  matcher = new PathMatcher("/accounts/:account_id")
  assert.deepEqual(
    matcher.pattern,
    ["accounts", {name: "account_id"}]
  )
  result = matcher.match("/accounts/54321",)
  assert.deepEqual(
    result,
    {account_id: "54321"}
  )
  assert.equal(
    matcher.match("/bogus/12345"),
    false
  )
  assert.equal(
    matcher.match("/accounts/12345/channels"),
    false
  )

test "Path matching, capturing middle component", ->
  matcher = new PathMatcher("/accounts/:account_id/channels")
  assert.deepEqual(
    matcher.pattern,
    ["accounts", {name: "account_id"}, "channels"]
  )

test "Path matching, capturing multiple components", ->
  matcher = new PathMatcher("/accounts/:account_id/channels/:channel_id")
  assert.deepEqual(
    matcher.pattern,
    ["accounts", {name: "account_id"}, "channels", {name: "channel_id"}]
  )
  assert.deepEqual(
    matcher.match("/accounts/54321/channels/abcdefg"),
    {account_id: "54321", channel_id: "abcdefg"}
  )


{'fraction_non_alphanumeric': 0.16734033953112368, 'fraction_numerical': 0.024252223120452707, 'mean_word_length': 3.7872340425531914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '2464094', 'n_tokens_mistral': 880, 'n_tokens_neox': 846, 'n_words': 148}