<commit_before>package bytecode

import (
	"github.com/goby-lang/goby/lexer"
	"github.com/goby-lang/goby/parser"
	"strings"
	"testing"
)

func TestNamespacedClass(t *testing.T) {
	input := `
	module Foo
	  class Bar
	    def bar
	      10
	    end
	  end
	end

	Foo::Bar.new.bar
	`

	expected := `
<Def:bar>
0 putobject 10
1 leave
<DefClass:Bar>
0 putself
1 putstring "bar"
2 def_method 0
3 leave
<DefClass:Foo>
0 putself
1 def_class class:Bar
2 pop
3 leave
<ProgramStart>
0 putself
1 def_class module:Foo
2 pop
3 getconstant Foo
4 getconstant Bar
5 send new 0
6 send bar 0
7 leave
	`

	bytecode := compileToBytecode(input)
	compareBytecode(t, bytecode, expected)
}

func TestRequireRelativeCompilation(t *testing.T) {
	input := `
	require_relative("foo")

	Foo.bar
	`

	expected := `
<ProgramStart>
0 putself
1 putstring "foo"
2 send require_relative 1
3 getconstant Foo
4 send bar 0
5 leave
`

	bytecode := compileToBytecode(input)
	compareBytecode(t, bytecode, expected)<commit_msg>Improve bytecode's namespace test.<commit_after>package bytecode

import (
	"github.com/goby-lang/goby/lexer"
	"github.com/goby-lang/goby/parser"
	"strings"
	"testing"
)

func TestNamespacedClass(t *testing.T) {
	input := `
	module Foo
	  class Bar
	    class Baz
	      10
	    end
	  end
	end

	Foo::Bar::Baz.new.bar
	`

	expected := `
<DefClass:Baz>
0 putobject 10
1 leave
<DefClass:Bar>
0 putself
1 def_class class:Baz
2 pop
3 leave
<DefClass:Foo>
0 putself
1 def_class class:Bar
2 pop
3 leave
<ProgramStart>
0 putself
1 def_class module:Foo
2 pop
3 getconstant Foo
4 getconstant Bar
5 getconstant Baz
6 send new 0
7 send bar 0
8 leave
`

	bytecode := compileToBytecode(input)
	compareBytecode(t, bytecode, expected)
}

func TestRequireRelativeCompilation(t *testing.T) {
	input := `
	require_relative("foo")

	Foo.bar
	`

	expected := `
<ProgramStart>
0 putself
1 putstring "foo"
2 send require_relative 1
3 getconstant Foo
4 send bar 0
5 leave
`

	bytecode := compileToBytecode(input)
	compareBytecode(t, bytecode, expected)
{'fraction_non_alphanumeric': 0.09478908188585608, 'fraction_numerical': 0.032754342431761785, 'mean_word_length': 4.090909090909091, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3712776', 'n_tokens_mistral': 806, 'n_tokens_neox': 749, 'n_words': 224}