File: fmt_longlong.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (32 lines) | stat: -rw-r--r-- 993 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "fmt.h"
#include "str.h"
#include <assert.h>
#include "scan.h"
#include <byte.h>

int main() {
  char buf[1024];
  long long l;

  assert(fmt_longlong(0,12345)==5);
  assert(fmt_longlong(0,-12345)==6);
  assert(fmt_longlong(buf,12345)==5); buf[5]=0;
  assert(str_equal(buf,"12345"));
  assert(scan_longlong(buf,&l)==5); assert(l==12345);
  assert(fmt_longlong(buf,-12345)==6); buf[6]=0;
  assert(str_equal(buf,"-12345"));
  assert(scan_longlong(buf,&l)==6); assert(l==-12345);

  assert(fmt_longlong(0,1234567890)==10);
  assert(fmt_longlong(0,-1234567890)==11);
  assert(fmt_longlong(buf,1234567890)==10); buf[10]=0;
  assert(str_equal(buf,"1234567890"));
  assert(scan_longlong(buf,&l)==10); assert(l==1234567890);

  assert(fmt_longlong(buf,-1234567890)==11); buf[11]=0;
  assert(str_equal(buf,"-1234567890"));
  assert(scan_longlong(buf,&l)==11); assert(l==-1234567890);

  assert(fmt_xlonglong(buf,0x8000000000000000)==16 && byte_equal(buf,16,"8000000000000000"));
  return 0;
}