<commit_before>require "rubygems"
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))

module CTest
  extend FFI::Library
  
  attach_function :strcat, [:pointer, :pointer], :pointer
end

describe MemoryPointer do
  it "makes a pointer from a string" do
    m = MemoryPointer.from_string("FFI is Awesome")
    m.type_size.should == 15
  end
  
  it "makes a pointer for a certain number of bytes" do
    m = MemoryPointer.new(8)
    m.write_array_of_int([1,2])
    m.read_array_of_int(2).should == [1,2]
  end

  it "allows access to an element of the pointer (as an array)" do
    m = MemoryPointer.new(:int, 2)
    m.write_array_of_int([1,2])
    m[0].read_int.should == 1
    m[1].read_int.should == 2
  end
  
  it "allows writing as an int" do
    m = MemoryPointer.new(:int)
    m.write_int(1)
    m.read_int.should == 1
  end
  
  it "allows writing as a long" do
    m = MemoryPointer.new(:long)
    m.write_long(10)<commit_msg>Added a spec for ints being read as strings<commit_after>require "rubygems"
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))

module CTest
  extend FFI::Library
  
  attach_function :strcat, [:pointer, :pointer], :pointer
end

describe MemoryPointer do
  it "makes a pointer from a string" do
    m = MemoryPointer.from_string("FFI is Awesome")
    m.type_size.should == 15
  end
  
  it "reads back a string" do
    m = MemoryPointer.from_string("FFI is Awesome")
    m.read_string.should == "FFI is Awesome"
  end
  
  it "reads back a string from an Array of ints" do
    m = MemoryPointer.new(:int, 4)
    m.write_array_of_int([541673030, 1092645737, 1869833591, 538994029])
    m.read_string(16).should == "FFI is Awesome  "
  end
  
  it "makes a pointer for a certain number of bytes" do
    m = MemoryPointer.new(8)
    m.write_array_of_int([1,2])
    m.read_array_of_int(2).should == [1,2]
  end

  it "allows access to an element of the pointer (as an array)" do
    m = MemoryPointer.new(:int, 2)
    m.write_array_of_int([1,2])
    m[0].read_int.should == 1
    m[1].read_int.should == 2
  end
  
  it "allows writing as an int" do
    m = MemoryPointer.new(:int)
    m.write_int(1)
    m.read_int.should == 1
  end
  
  it "allows writing as a long" do
    m = MemoryPointer.new(:long)
    m.write_long(10)
{'fraction_non_alphanumeric': 0.11458333333333333, 'fraction_numerical': 0.03428819444444445, 'mean_word_length': 3.332706766917293, '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': '5154472', 'n_tokens_mistral': 896, 'n_tokens_neox': 833, 'n_words': 235}