<commit_before>Liquid = requireLiquid()
Promise = require "native-or-bluebird"

asyncResult = (result) ->
  Promise.resolve(result).delay(1)

describe "Futures", ->
  it "are supported as simple variables", ->
    renderTest 'worked', '{{ test }}', test: asyncResult("worked")

  it "are supported as complex variables", ->
    renderTest 'worked', '{{ test.text }}', test: asyncResult(text: "worked")

  it "are supported as filter input", ->
    renderTest 'WORKED', '{{ test | upcase }}', test: asyncResult("worked")

  it "are supported as filter arguments", ->
    renderTest '1-2-3', '{{ array | join:minus }}',
      minus: asyncResult("-")
      array: [1, 2, 3]

  it "are supported as filter arguments", ->
    renderTest '1+2+3', '{{ array | join:minus | split:minus | join:plus }}',
      minus: asyncResult("-")
      plus: asyncResult("+")
      array: [1, 2, 3]
<commit_msg>Native promises don't support .delay<commit_after>Liquid = requireLiquid()
Promise = require "native-or-bluebird"

asyncResult = (result, delay = 1) ->
  new Promise (resolve) ->
    onTimeout = -> resolve(result)
    setTimeout onTimeout, delay

describe "Futures", ->
  it "are supported as simple variables", ->
    renderTest 'worked', '{{ test }}', test: asyncResult("worked")

  it "are supported as complex variables", ->
    renderTest 'worked', '{{ test.text }}', test: asyncResult(text: "worked")

  it "are supported as filter input", ->
    renderTest 'WORKED', '{{ test | upcase }}', test: asyncResult("worked")

  it "are supported as filter arguments", ->
    renderTest '1-2-3', '{{ array | join:minus }}',
      minus: asyncResult("-")
      array: [1, 2, 3]

  it "are supported as filter arguments", ->
    renderTest '1+2+3', '{{ array | join:minus | split:minus | join:plus }}',
      minus: asyncResult("-")
      plus: asyncResult("+")
      array: [1, 2, 3]

{'fraction_non_alphanumeric': 0.17530732228754678, 'fraction_numerical': 0.01389631213254944, 'mean_word_length': 3.5995085995085994, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '6917792', 'n_tokens_mistral': 610, 'n_tokens_neox': 580, 'n_words': 175}