Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Add test to CharIO #89

Closed

Conversation

errordeveloper
Copy link
Member

No description provided.

@@ -25,6 +25,7 @@ use core::mem::zeroed;

use lib::strconv;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line.

@farcaller
Copy link
Member

assert!(io.getc() != '0');
assert!(io.getc() == 'a');

This double assertion doesn't make sense, the second line is enough.

io.puti(11);
assert!(io.getc() == '1');

This test, if done right, should check that putc is called twice with '1', otherwise it doesn't make much sense, checks with 3 and 9 are enough.

The test case puts_should_leave_us_with_just_the_last_char doesn't really check that much (while it does check the condition it's named after).

TestCharIO { lastchar: Cell::new('0') }
}
fn getc(&self) -> char {
self.lastchar.get()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@farcaller which one do you prefer:

fn getc(&self) -> char {
  self.lastchar.get()
}

or:

fn getc(&self) -> char {
  return self.lastchar.get();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first one.

@errordeveloper
Copy link
Member Author

@farcaller sure, I though of checking how many times putc was called, not quite sure how to check that though... perhaps I need to add a counter in TestCharIO struct and then a getter for it as well?

@errordeveloper
Copy link
Member Author

I removed redundant assertions.

@errordeveloper
Copy link
Member Author

RE puts_should_leave_us_with_just_the_last_char, you are right...
May be I could make one test that would call pust, check the last character and check how many times putc was called?

@farcaller
Copy link
Member

perhaps I need to add a counter in TestCharIO struct and then a getter for it as well?

Yes, that's quite a good option.

@errordeveloper
Copy link
Member Author

@farcaller I think this is going to be all part of #80 now... closing. Reopen if you want it separate.

@errordeveloper errordeveloper deleted the add_chario_tests branch July 7, 2014 07:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants