-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created test code for parsing JSON files into JSON objects and then into Game objects. #599
Conversation
…d_rooms.wdl' in the tests directory
…chiventure into wdl/json_parse_test
…s to code. Fixed warnings of unused inputs in code.
…r to have parsing occur in separate function from main.
… will add rooms to the game.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. I tested the code before all of the game stuff got added and the code works. This code should work when the makefile error is fixed. However, I don't know enough about game state to fix the error of a missing game.h file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start in terms of practicing with the json parsing library, but needs a couple modifications before it'll be useful in the sandbox. Also, I've suggested a stopgap solution to your makefile issue.
src/wdl/sandbox/parser.c
Outdated
|
||
|
||
/* DEBUG is 0 normally, 1 to print debugging statements */ | ||
#define DEBUG 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to change to 0 before this merges
src/wdl/sandbox/parser.c
Outdated
|
||
/* Helper function: to print debugging statements only when debugging */ | ||
int my_print(char *string) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete these excess spaces (lines 14 and 18)
src/wdl/sandbox/parser.c
Outdated
/* reads the input file */ | ||
fp = fopen(filename, "r"); | ||
assert(fp); | ||
fread(buffer, 4096, 1, fp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the file is empty?
src/wdl/sandbox/parser.c
Outdated
|
||
game_t *parse_wdl(char* filename) { | ||
FILE *fp; | ||
char buffer[4096]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please declare a macro for 4096
…if jsonobjs are libobjs, however makefile has problems
@MaxineK36 I had problems with implementing the workaround as you suggested. I got an error that says /usr/bin/ld: cannot find -l:ibgame-state.a when using -l:$libgame Also I was pretty certain that having an empty file would result in reading 0 bytes. This stackoverflow should confirm that: Also, I see that the this task is still part of sprint 2. Should this be changed? The ideal situation would (I'm guessing) to do something at the start of this sprint. But what action should be done now? |
@dtbukowski It's ok that this is still assigned to sprint2 since it's associated with a sprint2 issue. re: Makefile: It looks like there were just a few typos in the Makefile, but I just pushed a commit that should resolve this and allow "make" to function properly. Now that this is working, I'm going to go through and review this PR again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make is now working, and I've noticed a couple of other things that need fixing.
|
||
int add_rooms_to_game(json_object *rooms, game_t *g) { | ||
|
||
//initializes json_objects for use in making room_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments referring to multiple lines of code should be block comments
(/* Some comment here */
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed all of the code that should be block comments
I implemented all of the small fix-ups that Maxine did. An error message shows when there are no arguments. Also got rid of a warning by using the return result of fread to get number of bytes parsed, where if it equals zero then the file is empty. |
… parsed from the returned game object. Also fixed fread file so that empty file text only displays when file is actually empty.
I added actual code that will show the game object and rooms were properly parsed by the code. This should make the code complete for the purposes of being a demonstration of the ease of parsing JSON files into game objects (or any other type of objects we want to convert it to). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! This should be helpful as you continue working on the parser for wdl++.
Issue Score: ✔️ Comments:
|
This code has successfully been merged into the dev branch. It should now act as a basis for how we can implement parsing JSON files into code. With this, this pull request is officially closed. |
I have written test code in a sandbox directory in src/wdl that can be used to test parsing JSON objects (Explained in further detail in #485.
This code currently faces compiler errors as I was unable to figure out how to integrate the necessary code from the game-state using the Makefile. I suspect that, because of the switch from Make to CMake, there is no longer a Makefile that can make the game-state files into executables for me to be able to use for the test.
However, apart from being unable to integrate the game-state functions, the code should be functional once the Makefile issue is resolved.
Closes #485.