<commit_before>package command

import (
	"testing"

	"gomock.googlecode.com/hg/gomock"

	"chunkymonkey/gamerules"
	"testmatcher"
)

func TestCommandFramework(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	mockGame := gamerules.NewMockIGame(mockCtrl)

	cf := NewCommandFramework("/")

	mockGame.EXPECT().BroadcastMessage("§dthis is a broadcast")
	cf.Process("thePlayer", "/say this is a broadcast", mockGame)

	mockGame.EXPECT().IsValidPlayerName("thePlayer").Return(true)
	mockGame.EXPECT().IsValidItemId(1).Return(true)
	mockGame.EXPECT().SendMessageToPlayer("thePlayer", "Giving 64 of 1 to thePlayer")
	mockGame.EXPECT().GiveItem("thePlayer", 1, 64, 0)
	cf.Process("thePlayer", "/give thePlayer 1 64", mockGame)

	mockGame.EXPECT().IsValidPlayerName("otherPlayer").Return(false)
	mockGame.EXPECT().SendMessageToPlayer("thePlayer", "'otherPlayer' is not logged in")
	cf.Process("thePlayer", "/give otherPlayer 1 64", mockGame)

	mockGame.EXPECT().IsValidPlayerName("otherPlayer").Return(true)
	mockGame.EXPECT().IsValidItemId(1).Return(false)
	mockGame.EXPECT().SendMessageToPlayer("thePlayer", "'1' is not a valid item id")
	cf.Process("thePlayer", "/give otherPlayer 1 64", mockGame)

	mockGame.EXPECT().IsValidPlayerName("otherPlayer").Return(true)
	mockGame.EXPECT().IsValidItemId(1).Return(true)
	mockGame.EXPECT().SendMessageToPlayer("thePlayer", "Cannot give more than 512 items at once")
	cf.Process("thePlayer", "/give otherPlayer 1 513", mockGame)

	mockGame.EXPECT().SendMessageToPlayer("thePlayer", &testmatcher.StringPrefix{"Commands:"})
	cf.Process("thePlayer", "/help", mockGame)

	gomock.InOrder(
		mockGame.EXPECT().SendMessageToPlayer("thePlayer", "Command: /help"),
		mockGame.EXPECT().SendMessageToPlayer("thePlayer", "Usage: help|?"),
		mockGame.EXPECT().SendMessageToPlayer("thePlayer", "Description: Shows a list of all commands."),
	)
	cf.Process("thePlayer", "/help help", mockGame)
}<commit_msg>Tests compile, but are not all passing yet<commit_after>package command

import (
	"testing"

	"gomock.googlecode.com/hg/gomock"

	"chunkymonkey/gamerules"
	"testmatcher"
)

func TestCommandFramework(t *testing.T) {
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

	mockGame := gamerules.NewMockIGame(mockCtrl)
	mockPlayer := gamerules.NewMockIPlayerClient(mockCtrl)
	mockOther := gamerules.NewMockIPlayerClient(mockCtrl)

	cf := NewCommandFramework("/")

	mockGame.EXPECT().BroadcastMessage("§dthis is a broadcast")
	cf.Process(mockPlayer, "/say this is a broadcast", mockGame)

	mockGame.EXPECT().PlayerByName("thePlayer").Return(mockPlayer)
	mockGame.EXPECT().ItemTypeById(1)
	mockPlayer.EXPECT().EchoMessage("Giving 64 of 1 to thePlayer")
	mockPlayer.EXPECT().GiveItemAtPosition("thePlayer", gamerules.Slot{1, 64, 0})
	cf.Process(mockPlayer, "/give thePlayer 1 64", mockGame)

	mockGame.EXPECT().PlayerByName("otherPlayer")
	mockPlayer.EXPECT().EchoMessage("'otherPlayer' is not logged in")
	cf.Process(mockPlayer, "/give otherPlayer 1 64", mockGame)

	mockGame.EXPECT().PlayerByName("otherPlayer").Return(mockOther)
	mockGame.EXPECT().ItemTypeById(1).Return(gamerules.ItemType{}, false)
	mockPlayer.EXPECT().EchoMessage("'1' is not a valid item id")
	cf.Process(mockPlayer, "/give otherPlayer 1 64", mockGame)

	mockGame.EXPECT().PlayerByName("otherPlayer").Return(mockOther)
	mockGame.EXPECT().ItemTypeById(1)
	mockPlayer.EXPECT().EchoMessage("Cannot give more than 512 items at once")
	cf.Process(mockPlayer, "/give otherPlayer 1 513", mockGame)

	mockPlayer.EXPECT().EchoMessage(&testmatcher.StringPrefix{"Commands:"})
	cf.Process(mockPlayer, "/help", mockGame)

	gomock.InOrder(
		mockPlayer.EXPECT().EchoMessage("Command: /help"),
		mockPlayer.EXPECT().EchoMessage("Usage: help|?"),
		mockPlayer.EXPECT().EchoMessage("Description: Shows a list of all commands."),
	)
	cf.Process(mockPlayer, "/help help", mockGame)
}
{'fraction_non_alphanumeric': 0.15426078028747434, 'fraction_numerical': 0.013860369609856264, 'mean_word_length': 6.825301204819277, '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': '2973777', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1278, 'n_words': 241}