<commit_before>Dir.chdir File.join File.dirname(__FILE__), '../../'
require './lib/flok'
require './spec/env/etc'

RSpec.describe "lib/services_compiler" do
  #Return a v8 instance of a compiled js file
  def compile fn
    compiler = Flok::ServicesCompiler
    js_src(fn)
    js_res = compiler.compile(js_src(fn))
    ctx = V8::Context.new
    ctx.eval js_res

    ctx
  end

  #Get the source for a file in  ./service_compiler/*.rb
  def js_src fn
    Dir.chdir File.join(File.dirname(__FILE__), "service_compiler") do
      return File.read(fn+'.rb')
    end
  end

  it "Does fail to compile a controller with a non-existant type" do
    expect { compile "service_bad_type" }.to raise_exception
  end

  it "Can call compile method and get a copy of all the functions" do
    ctx = compile "service0"

    #on_wakeup
    res = ctx.eval("test_on_wakeup")
    expect(res).not_to eq(nil)

    #on_sleep
    res = ctx.eval("test_on_sleep")
    expect(res).not_to eq(nil)

    #on_connect
    res = ctx.eval("test_on_connect");
    expect(res).not_to eq(nil)

    #on_disconnect
    res = ctx.eval("test_on_disconnect")
    expect(res).not_to eq(nil)

    #on_event
    ################################################################
    res = ctx.eval("test_on_hello");
    expect(res).not_to eq(nil)
    ################################################################
  end
end<commit_msg>Added more to service spec<commit_after>Dir.chdir File.join File.dirname(__FILE__), '../../'
require './lib/flok'
require './spec/env/etc'

RSpec.describe "lib/services_compiler" do
  #Return a v8 instance of a compiled js file
  def compile fn
    compiler = Flok::ServicesCompiler
    js_src(fn)
    js_res = compiler.compile(js_src(fn))
    ctx = V8::Context.new
    ctx.eval js_res

    ctx
  end

  #Get the source for a file in  ./service_compiler/*.rb
  def js_src fn
    Dir.chdir File.join(File.dirname(__FILE__), "service_compiler") do
      return File.read(fn+'.rb')
    end
  end

  it "Does fail to compile a controller with a non-existant type" do
    expect { compile "service_bad_type" }.to raise_exception
  end

  it "Can call compile method and get a copy of all the functions" do
    ctx = compile "service0"

    #on_wakeup
    res = ctx.eval("test_on_wakeup")
    expect(res).not_to eq(nil)

    #on_sleep
    res = ctx.eval("test_on_sleep")
    expect(res).not_to eq(nil)

    #on_connect
    res = ctx.eval("test_on_connect");
    expect(res).not_to eq(nil)

    #on_disconnect
    res = ctx.eval("test_on_disconnect")
    expect(res).not_to eq(nil)

    #on_event
    res = ctx.eval("test_on_hello");
    expect(res).not_to eq(nil)

    #on_handle_timer_events
    res = ctx.eval("test_handle_timer_events");
    expect(res).not_to eq(nil)
  end
end
{'fraction_non_alphanumeric': 0.15720997470184314, 'fraction_numerical': 0.0021684134441633538, 'mean_word_length': 3.311526479750779, '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': '5609874', 'n_tokens_mistral': 957, 'n_tokens_neox': 931, 'n_words': 236}